util

package
v0.0.0-...-ac2fd71 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RemoveAttempts = 3
	RemoveWait     = time.Millisecond
)

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 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 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).

Types

This section is empty.

Jump to

Keyboard shortcuts

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