testutil

package module
v0.52.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package testutil provides various helper functions for tests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertTrueBeforeTimeout

func AssertTrueBeforeTimeout(t *testing.T, frequency, timeout time.Duration, condition func() bool)

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 Detab

func Detab(str string) string

Detab removes whitespace from the front of a string on every line

func Fuzz

func Fuzz(t *testing.T, test func(int64))

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 RequireTrueBeforeTimeout

func RequireTrueBeforeTimeout(t *testing.T, frequency, timeout time.Duration, condition func() bool)

RequireTrueBeforeTimeout is the same as AssertTrueBeforeTimeout, but it calls t.failNow() if the condition function times out.

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

func (*TempFolder) RemoveAll

func (f *TempFolder) RemoveAll() error

RemoveAll purges a TempFolder

Directories

Path Synopsis
Package flake marks an instance of testing.TB(https://pkg.go.dev/testing#TB) as flake.
Package flake marks an instance of testing.TB(https://pkg.go.dev/testing#TB) as flake.

Jump to

Keyboard shortcuts

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