Documentation ¶
Index ¶
- Constants
- func CleanName(n string) string
- func Context(ctx context.Context, tb testing.TB) context.Context
- func IsTestReExec() bool
- func PrintAdditionalBenchmarkConfig()
- func RandNameSuffix(xs ...any) (s string)
- func RemoveAll(p string) (err error)
- func RunInReExec(ctx context.Context, tb testing.TB, f func(context.Context, testing.TB))
- func RunningBenchmarks() bool
- func TestNameRegex(tb testing.TB) string
Constants ¶
const ( RemoveAttempts = 3 RemoveWait = time.Millisecond )
const ReExecEnv = "HCSSHIM_TEST_RE_EXEC"
ReExecEnv is used to indicate that the current testing binary has been re-execed.
Tests should set this environment variable before re-execing themselves.
Variables ¶
This section is empty.
Functions ¶
func CleanName ¶
CleanName returns a string appropriate for uVM, container, or file names.
Based on testing.TB.TempDir.
func Context ¶
Context creates a context.Context that uses the testing.Deadline minus a small grace period (if applicable) and the cancellation to the testing cleanup.
Based heavily on (copied directly from): Go lang's src/internal/testenv/Command.Context https://cs.opensource.google/go/go/+/master:src/internal/testenv/exec.go;l=133;drc=5613882df7555484680ecabc0462b7c23c6f5205
func IsTestReExec ¶
func IsTestReExec() bool
IsTestReExec checks if the current test execution is a re-exec of a testing binary. I.e., it checks if the ReExecEnv environment variable is set.
func PrintAdditionalBenchmarkConfig ¶
func PrintAdditionalBenchmarkConfig()
For default configuration printed, see: [testing.(*B).Run()] in src/testing/benchmark.go
func RandNameSuffix ¶
RandNameSuffix concats the provided parameters, and appends a random 4 byte sequence as hex string.
This is to ensure uniqueness when creating uVMs or containers across multiple test runs (benchmark iterations), where the test (benchmark) name is already used as the ID.
func RemoveAll ¶
RemoveAll tries RemoveAttempts times to remove the path via os.RemoveAll, waiting RemoveWait between attempts.
func RunInReExec ¶
RunInReExec checks if it is executing in within a re-exec (via IsTestReExec) and, if so, calls f and then testing.TB.Skip to skip the remainder of the test.
func RunningBenchmarks ¶
func RunningBenchmarks() bool
RunningBenchmarks returns whether benchmarks were requested to be run.
Returning true implies the current executable is a testing binary (either built or run by `go test`).
Should not be called from init() or global variable initialization since there is no guarantee on if the testing flags have been defined yet (and ideally should be called after flag.Parse).
func TestNameRegex ¶
TestNameRegex returns a regex expresion that matches the current test name exactly.
`-test.run regex` matches the individual test name components be splitting on `/`. So `A/B` will first match test names against `A`, and then, for all matched tests, match sub-tests against `B`. Therefore, for a test named `foo/bar`, return `^foo$/^bar$`.
See: `go help test`.
Types ¶
This section is empty.