util

package
v0.0.0-...-9cf7c1c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RemoveAttempts = 3
	RemoveWait     = time.Millisecond
)
View Source
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

func CleanName(n string) string

CleanName returns a string appropriate for uVM, container, or file names.

Based on testing.TB.TempDir.

func Context

func Context(ctx context.Context, tb testing.TB) context.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

func RandNameSuffix(xs ...any) (s string)

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

func RemoveAll(p string) (err error)

RemoveAll tries RemoveAttempts times to remove the path via os.RemoveAll, waiting RemoveWait between attempts.

func RunInReExec

func RunInReExec(ctx context.Context, tb testing.TB, f func(context.Context, testing.TB))

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

func TestNameRegex(tb testing.TB) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL