Documentation
¶
Overview ¶
Package testt (for test tools), provides a couple of useful helpers for common test patterns. To be used as a optional companion of the assert/check library.
Index ¶
- func Context(t testing.TB) context.Context
- func ContextWithTimeout(t testing.TB, dur time.Duration) context.Context
- func Log(t testing.TB, args ...any)
- func Logf(t testing.TB, format string, args ...any)
- func Must[T any](out T, err error) func(t testing.TB) T
- func Ticker(t testing.TB, dur time.Duration) *time.Ticker
- func Timer(t testing.TB, dur time.Duration) *time.Timer
- func WithEnv(t *testing.T, key, value string, op func())
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Context ¶
Context creates a context and attaches its cancellation function to the test execution's Cleanup. Given the execution of tests, this means that the context is canceled *after* the test functions defers have run.
func ContextWithTimeout ¶
ContextWithTimeout creates a context with the specified timeout, and attaches the cancellation to the test execution's cleanup.
func Must ¶ added in v0.10.0
Must is used to capture the output of a function that returns an error and an arbitry value and simplify call sites in test code. The function that returns makes a fatal assertion if the error is non-nil, and returns the object.
func Ticker ¶
Ticker creates a new time.Ticker with the specified interval, and manages the cleanup of the ticker.
func Timer ¶
Timer creates a new time.Timer with the specified starting duration, and manages the cleanup of the timer.
func WithEnv ¶ added in v0.10.3
WithEnv sets an environment variable according to the key-value pair, and then and runs a function with that environment variable set. When WithEnv returns the state of the current process's environment.
WithEnv will assert if there are any problems setting environment variables. Callers are responsible for managing concurrency between multiple.
Types ¶
This section is empty.