Documentation
¶
Overview ¶
Package testutil provides various helper functions for tests
Package testutil provides utilities for testing.
Index ¶
- func AssertTrueBeforeTimeout(t *testing.T, frequency, timeout time.Duration, condition func() bool)
- func Detab(str string) string
- func ElementsMatchFn[K comparable, V any](t assert.TestingT, seq iter.Seq2[K, V], ...)
- func Fuzz(t *testing.T, test func(int64))
- func IsolatedGoBuildCmd(cacheDir string, output string, args ...string) *exec.Cmd
- func IsolatedGoBuildEnv(cacheDir string) map[string]string
- func RequireTrueBeforeTimeout(t *testing.T, frequency, timeout time.Duration, condition func() bool)
- type TempFolder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertTrueBeforeTimeout ¶
AssertTrueBeforeTimeout regularly checks whether a condition is met. It does so until a timeout is reached, in which case it makes the test fail. Condition is evaluated in a goroutine to avoid tests hanging if a system is deadlocked.
func ElementsMatchFn ¶ added in v0.74.0
func ElementsMatchFn[K comparable, V any]( t assert.TestingT, seq iter.Seq2[K, V], matchers ...func(require.TestingT, K, V), )
ElementsMatchFn checks that for each element there is exactly one matcher function that does not fail. Order of elements and matchers does not matter.
Using require instead of assert in the matchers will produce more compact and readable failures.
seq can be obtained from slices.All() or maps.All().
func Fuzz ¶
Fuzz implements poor-soul's attempt at fuzzing. The idea is to catch edge cases by running a bunch of random, but deterministic (the same on every run), scenarios. In "-short" mode it runs for about 100ms; otherwise about 1s.
The `test` function should use its input as a seed to a random number generator.
func IsolatedGoBuildCmd ¶ added in v0.75.0
IsolatedGoBuildCmd creates a "go build" command with isolated build environment. This may help reduce timeouts and flakiness when running tests with high parallelism.
cacheDir is the directory to use for GOCACHE. output is the path for the output binary. args are additional arguments to pass to "go build" (e.g., "-tags", "foo", "source.go").
func IsolatedGoBuildEnv ¶ added in v0.75.0
IsolatedGoBuildEnv returns environment variables for isolated Go build operations. This may help reduce timeouts and flakiness when running tests with high parallelism.
cacheDir is the directory to use for GOCACHE.
Types ¶
type TempFolder ¶
type TempFolder struct {
RootPath string
}
TempFolder is a temporary folder used for testing
func NewTempFolder ¶
func NewTempFolder(namePrefix string) (*TempFolder, error)
NewTempFolder creates a new temporary folder
func (*TempFolder) Add ¶
func (f *TempFolder) Add(fileName string, contents string) error
Add adds a file to a temp folder
func (*TempFolder) Delete ¶
func (f *TempFolder) Delete(fileName string) error
Delete removes a specific file