Documentation
¶
Index ¶
Constants ¶
const ExpectPreconditionsMet = "DEVNET_EXPECT_PRECONDITIONS_MET"
Variables ¶
var DefaultTestLogLevel = log.LevelInfo
DefaultTestLogLevel is set to info level to show relevant logs without being overly verbose unless configured otherwise.
var ( // RootContext is the context that is used for the root of the test suite. // It should be set for good before any tests are run. RootContext = context.Background() )
Functions ¶
func AddTestScope ¶ added in v1.13.4
AddTestScope combines the sub-scope with the test-scope of the context, and returns a context with the updated scope value.
func RunParallel ¶
RunParallel runs the test-function, for each of the given elements, in parallel. This awaits the result of all sub-tests to complete, by grouping everything into a regular sub-test.
Types ¶
type CommonT ¶
type CommonT interface {
Error(args ...any)
Errorf(format string, args ...any)
Fail()
FailNow()
SkipNow()
TempDir() string
Cleanup(fn func())
Log(args ...any)
Logf(format string, args ...any)
Helper()
Name() string
Logger() log.Logger
Tracer() trace.Tracer
Ctx() context.Context
Require() *testreq.Assertions
}
CommonT is a subset of testing.T, extended with a few common utils. This interface should not be used directly. Instead, use T in test-scope, or P when operating at package level.
This CommonT interface is minimal enough such that it can be implemented by tooling, and a *testing.T can be used with minimal wrapping.
type P ¶
type P interface {
CommonT
// WithCtx makes a copy of P with a specific context.
// The ctx must match the test-scope of the existing context.
// This function is used to create a P with annotated context, e.g. a specific resource.
WithCtx(ctx context.Context) P
// TempDir creates a temporary directory, and returns the file-path.
// This directory is cleaned up at the end of the package,
// and can be shared safely between tests that run in that package scope.
TempDir() string
// Cleanup runs the given function at the end of the package-scope.
// This function will clean-up once the package-level testing is fully complete.
// These resources can thus be shared safely between tests.
Cleanup(fn func())
// Close closes the testing handle. This cancels the context and runs all cleanup.
Close()
// contains filtered or unexported methods
}
P is used by the preset package and system backends as testing interface, to host package-wide resources.
type T ¶
type T interface {
CommonT
// TempDir creates a temporary directory, and returns the file-path.
// This directory is cleaned up at the end of the test, and must not be shared between tests.
TempDir() string
// Cleanup runs the given function at the end of the test-scope,
// or at the end of the sub-test (if this is a nested test).
// This function will clean-up before the package-level testing scope may be complete.
// Do not use the test-scope cleanup with shared resources.
Cleanup(fn func())
// Run runs the given function in as a sub-test.
Run(name string, fn func(T))
// Ctx returns a context that will be canceled at the end of this (sub) test-scope,
// and inherits the context of the parent-test-scope.
Ctx() context.Context
// WithCtx makes a copy of T with a specific context.
// The ctx must match the test-scope of the existing context.
// This function is used to create a T with annotated context, e.g. a specific resource, rather than a sub-scope.
WithCtx(ctx context.Context) T
// Parallel signals that this test is to be run in parallel with (and only with) other parallel tests.
Parallel()
// Skip is equivalent to Log followed by SkipNow.
Skip(args ...any)
// Skipped reports whether the test was skipped.
Skipped() bool
// Skipf is equivalent to Logf followed by SkipNow.
Skipf(format string, args ...any)
// SkipNow marks the test as skipped and stops test execution.
// It is remapped to FailNow if the env var DEVNET_EXPECT_PRECONDITIONS_MET is set to true.
SkipNow()
// Gate provides everything that Require does, but skips instead of fails the test upon error.
Gate() *testreq.Assertions
// Deadline reports the time at which the test binary will have
// exceeded the timeout specified by the -timeout flag.
//
// The ok result is false if the -timeout flag indicates "no timeout" (0).
Deadline() (deadline time.Time, ok bool)
// This distinguishes the interface from other testing interfaces,
// such as the one used at package-level for shared system construction.
TestOnly()
}