istio: istio.io/istio/pkg/test/framework Index | Files | Directories

package framework

import "istio.io/istio/pkg/test/framework"

Index

Package Files

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 Suite Uses

type Suite struct {
    // contains filtered or unexported fields
}

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(testID string, m *testing.M) *Suite

NewSuite returns a new suite instance.

func (*Suite) Label Uses

func (s *Suite) Label(labels ...label.Instance) *Suite

Label all the tests in suite with the given labels

func (*Suite) RequireEnvironment Uses

func (s *Suite) RequireEnvironment(name environment.Name) *Suite

RequireEnvironment ensures that the current environment matches what the suite expects. Otherwise it stops test execution. This also applies the appropriate label to the suite implicitly.

func (*Suite) RequireEnvironmentVersion Uses

func (s *Suite) RequireEnvironmentVersion(version string) *Suite

RequireEnvironmentVersion validates the environment meets a minimum version

func (*Suite) Run Uses

func (s *Suite) Run()

Run the suite. This method calls os.Exit and does not return.

func (*Suite) Setup Uses

func (s *Suite) Setup(fn resource.SetupFn) *Suite

Setup runs enqueues the given setup function to run before test execution.

func (*Suite) SetupOnEnv Uses

func (s *Suite) SetupOnEnv(e environment.Name, fn resource.SetupFn) *Suite

SetupOnEnv runs the given setup function conditionally, based on the current environment.

func (*Suite) Skip Uses

func (s *Suite) Skip(reason string) *Suite

Skip marks a suite as skipped with the given reason. This will prevent any setup functions from occurring.

type SuiteContext Uses

type SuiteContext interface {
    resource.Context
}

suiteContext contains suite-level items used during runtime.

type Test Uses

type Test struct {
    // contains filtered or unexported fields
}

Test allows the test author to specify test-related metadata in a fluent-style, before commencing execution.

func NewTest Uses

func NewTest(t *testing.T) *Test

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

func (*Test) Label Uses

func (t *Test) Label(labels ...label.Instance) *Test

Label applies the given labels to this test.

func (*Test) RequiresEnvironment Uses

func (t *Test) RequiresEnvironment(name environment.Name) *Test

RequiresEnvironment ensures that the current environment matches what the suite expects. Otherwise it stops test execution and skips the test.

func (*Test) Run Uses

func (t *Test) Run(fn func(ctx TestContext))

Run the test, supplied as a lambda.

func (*Test) RunParallel Uses

func (t *Test) RunParallel(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.

type TestContext Uses

type TestContext interface {
    resource.Context
    test.Failer

    // 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.
    WhenDone(fn func() error)

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

    // 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{})
    SkipNow()
    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.

Directories

PathSynopsis
components/bookinfo
components/chiron
components/citadel
components/deployment
components/echo
components/echo/common
components/echo/docker
components/echo/docker/images
components/echo/echoboot
components/echo/kube
components/environment
components/environment/api
components/environment/kube
components/environment/native
components/galley
components/ingress
components/istio
components/istioctl
components/mcpserver
components/mixer
components/namespace
components/pilot
components/policybackend
components/prometheus
components/redis
components/zipkin
core
core/image
errors
integration
label
resource

Package framework imports 27 packages (graph) and is imported by 2 packages. Updated 2019-12-11. Refresh now. Tools for package owners.