istio: Index | Files | Directories

package framework

import ""


Package Files

analyzer.go analyzer_runtime.go config.go initstatics.go logging.go operations.go resourceid.go runtime.go scope.go suite.go suitecontext.go test.go testcontext.go

func Run Uses

func Run(t *testing.T, fn func(ctx TestContext))

Run runs the given test.

type Outcome Uses

type Outcome string
const (
    Passed         Outcome = "Passed"
    Failed         Outcome = "Failed"
    Skipped        Outcome = "Skipped"
    NotImplemented Outcome = "NotImplemented"

type Suite Uses

type Suite interface {
    // EnvironmentFactory sets a custom function used for creating the resource.Environment for this Suite.
    EnvironmentFactory(fn resource.EnvironmentFactory) Suite
    // Label all the tests in suite with the given labels
    Label(labels ...label.Instance) Suite
    // Skip marks a suite as skipped with the given reason. This will prevent any setup functions from occurring.
    Skip(reason string) Suite
    // RequireMinClusters ensures that the current environment contains at least the given number of clusters.
    // Otherwise it stops test execution.
    RequireMinClusters(minClusters int) Suite
    // RequireMaxClusters ensures that the current environment contains at least the given number of clusters.
    // Otherwise it stops test execution.
    RequireMaxClusters(maxClusters int) Suite
    // RequireSingleCluster is a utility method that requires that there be exactly 1 cluster in the environment.
    RequireSingleCluster() Suite
    // RequireEnvironmentVersion validates the environment meets a minimum version
    RequireEnvironmentVersion(version string) Suite
    // Setup runs enqueues the given setup function to run before test execution.
    Setup(fn resource.SetupFn) Suite
    // Run the suite. This method calls os.Exit and does not return.

Suite allows the test author to specify suite-related metadata and do setup in a fluent-style, before commencing execution.

func NewSuite Uses

func NewSuite(m *testing.M) Suite

NewSuite returns a new suite instance.

type SuiteContext Uses

type SuiteContext interface {

suiteContext contains suite-level items used during runtime.

type SuiteOutcome Uses

type SuiteOutcome struct {
    Name         string
    Environment  string
    Multicluster bool
    TestOutcomes []TestOutcome

type Test Uses

type Test interface {
    // Label applies the given labels to this test.
    Label(labels ...label.Instance) Test
    // Label applies the given labels to this test.
    Features(feats ...features.Feature) Test
    NotImplementedYet(features ...features.Feature) Test
    // RequiresMinClusters ensures that the current environment contains at least the expected number of clusters.
    // Otherwise it stops test execution and skips the test.
    RequiresMinClusters(minClusters int) Test
    // RequiresMaxClusters ensures that the current environment contains at most the expected number of clusters.
    // Otherwise it stops test execution and skips the test.
    RequiresMaxClusters(maxClusters int) Test
    // RequiresSingleCluster this a utility that requires the min/max clusters to both = 1.
    RequiresSingleCluster() Test
    // Run the test, supplied as a lambda.
    Run(fn func(ctx TestContext))
    // RunParallel runs this test in parallel with other children of the same parent test/suite. Under the hood,
    // this relies on Go's t.Parallel() and will, therefore, have the same behavior.
    // A parallel test will run in parallel with siblings that share the same parent test. The parent test function
    // will exit before the parallel children are executed. It should be noted that if the parent test is prevented
    // from exiting (e.g. parent test is waiting for something to occur within the child test), the test will
    // deadlock.
    // Example:
    // func TestParallel(t *testing.T) {
    //     framework.NewTest(t).
    //         Run(func(ctx framework.TestContext) {
    //             ctx.NewSubTest("T1").
    //                 Run(func(ctx framework.TestContext) {
    //                     ctx.NewSubTest("T1a").
    //                         RunParallel(func(ctx framework.TestContext) {
    //                             // Run in parallel with T1b
    //                         })
    //                     ctx.NewSubTest("T1b").
    //                         RunParallel(func(ctx framework.TestContext) {
    //                             // Run in parallel with T1a
    //                         })
    //                     // Exits before T1a and T1b are run.
    //                 })
    //             ctx.NewSubTest("T2").
    //                 Run(func(ctx framework.TestContext) {
    //                     ctx.NewSubTest("T2a").
    //                         RunParallel(func(ctx framework.TestContext) {
    //                             // Run in parallel with T2b
    //                         })
    //                     ctx.NewSubTest("T2b").
    //                         RunParallel(func(ctx framework.TestContext) {
    //                             // Run in parallel with T2a
    //                         })
    //                     // Exits before T2a and T2b are run.
    //                 })
    //         })
    // }
    // In the example above, non-parallel parents T1 and T2 contain parallel children T1a, T1b, T2a, T2b.
    // Since both T1 and T2 are non-parallel, they are run synchronously: T1 followed by T2. After T1 exits,
    // T1a and T1b are run asynchronously with each other. After T1a and T1b complete, T2 is then run in the
    // same way: T2 exits, then T2a and T2b are run asynchronously to completion.
    RunParallel(fn func(ctx TestContext))

func NewTest Uses

func NewTest(t *testing.T) Test

NewTest returns a new test wrapper for running a single test.

type TestContext Uses

type TestContext interface {

    // NewSubTest creates a new sub-test under the current running Test. The lifecycle of a sub-Test is scoped to the
    // parent. Calls to Done() will block until all children are also Done(). When Run, sub-Tests will automatically
    // create their own Golang *testing.T with the name provided.
    // If this TestContext was not created by a Test or if that Test is not running, this method will panic.
    NewSubTest(name string) Test

    // WorkDir allocated for this test.
    WorkDir() string

    // CreateDirectoryOrFail creates a new sub directory with the given name in the workdir, or fails the test.
    CreateDirectoryOrFail(name string) string

    // CreateTmpDirectoryOrFail creates a new temporary directory with the given prefix in the workdir, or fails the test.
    CreateTmpDirectoryOrFail(prefix string) string

    // RequireOrSkip skips the test if the environment is not as expected.
    RequireOrSkip(envName environment.Name)

    // WhenDone runs the given function when the test context completes.
    // This function may not (safely) access the test context.
    WhenDone(fn func() error)

    // Done should be called when this context is no longer needed. It triggers the asynchronous cleanup of any
    // allocated resources.

    // Methods for interacting with the underlying *testing.T.
    Error(args ...interface{})
    Errorf(format string, args ...interface{})
    Failed() bool
    Log(args ...interface{})
    Logf(format string, args ...interface{})
    Name() string
    Skip(args ...interface{})
    Skipf(format string, args ...interface{})
    Skipped() bool

TestContext is a test-level context that can be created as part of test executing tests.

func NewContext Uses

func NewContext(goTest *testing.T, labels ...label.Instance) TestContext

NewContext creates a new test context and returns. It is up to the caller to close to context by calling .Done() at the end of the test run.

type TestOutcome Uses

type TestOutcome struct {
    Name          string
    Type          string
    Outcome       Outcome
    FeatureLabels map[features.Feature][]string



Package framework imports 29 packages (graph) and is imported by 3 packages. Updated 2020-07-03. Refresh now. Tools for package owners.