testutil

package
v2.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2019 License: ISC Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestMultiplier = "1.0"

TestMultiplier can be used to increase the default duration or integers used during test runs when waiting for time-sensitive values to be returned. It defaults to a multiplier of 1.0.

This is specifically useful on slower environments like a CI server.

Functions

func Exec

func Exec(tb testing.TB, wait string, runner func(tb testing.TB, cmd *exec.Cmd)) (string, error)

Exec runs the current executed test as an external command, setting the `RUN_WITH_EXEC` environment variable to `1`, waiting for the `wait` string to be printed on stderr (unless empty), executes the `runner` function, and returns the stderr output and the exit status of the command.

func Integration

func Integration(tb testing.TB)

Integration skips the test if the `-short` flag is specified. It also enforces the test name to starts with `Integration`, this allows to run _only_ integration tests using `-run '^TestIntegration'` or `-bench '^BenchmarkIntegration`.

func Logger

func Logger(tb testing.TB) *zap.Logger

Logger returns a Zap logger instance to use during testing. It returns logs in a user-friendly format, reporting anything above warn level.

DEPRECATED: this is now supported by Zap itself, since version `1.9.0`.

See: https://github.com/uber-go/zap/pull/518

func MultipliedDuration

func MultipliedDuration(tb testing.TB, d time.Duration) time.Duration

MultipliedDuration returns the provided duration, multiplied by the configured `TestMultiplier` variable.

func MultipliedInt

func MultipliedInt(tb testing.TB, i int) int

MultipliedInt returns the provided int, multiplied by the configured `TestMultiplier` variable. `TestMultiplier` is a float, but is converted to the next logical integer (ceiling).

func Random

func Random(tb testing.TB) string

Random returns a random string, to use during testing.

func Verbose

func Verbose(tb testing.TB) bool

Verbose returns true if the `testing.Verbose` flag returns true, or if the environment variable `CI` is set to any value. This allows you to see more verbose error reporting locally when running `go test -v ./...`, or on the CI by default.

func WithMultiplier

func WithMultiplier(tb testing.TB, f float64, fn func(tb testing.TB))

WithMultiplier runs the passed in function with the configured test multiplier. Note that this function is NOT thread-safe. If you call this function in tests that set `Parallel()`, you might get unexpected results.

Types

This section is empty.

Jump to

Keyboard shortcuts

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