Documentation ¶
Overview ¶
Package testutils provides general purpose utility functions for unit/integration testing.
Index ¶
- func FailOnTimeout(t *testing.T, done <-chan struct{}, timeout time.Duration)
- func SetEnv(t *testing.T, key string, val string)
- func SetFileContents(t *testing.T, filepath string, contents string)
- func SetFileContentsAndPermissions(t *testing.T, path string, contents string, perm fs.FileMode)
- type ErrorCache
- type Func
- type GivenStatement
- func (g GivenStatement) Branch(runners ...Runner) Runner
- func (g GivenStatement) Given(description string, setup func()) GivenStatement
- func (g GivenStatement) Given2(g2 GivenStatement) GivenStatement
- func (g GivenStatement) When(description string, setup func()) WhenStatement
- func (g GivenStatement) When2(w WhenStatement) WhenStatement
- type Runner
- type TestCases
- type ThenStatement
- type ThenStatements
- type WhenStatement
- func (w WhenStatement) Branch(runners ...Runner) Runner
- func (w WhenStatement) Then(description string, execution func(t *testing.T)) ThenStatement
- func (w WhenStatement) Then2(then ThenStatement) ThenStatement
- func (w WhenStatement) When(description string, setup func()) WhenStatement
- func (w WhenStatement) When2(w2 WhenStatement) WhenStatement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FailOnTimeout ¶
FailOnTimeout blocks until `done` is closed or until specified timeout has elapsed. In the latter case it calls require.FailNow(t, "test timed out").
func SetEnv ¶
SetEnv safely sets an OS env var to the specified value and resets it to the original value upon test closure
func SetFileContents ¶
SetFileContents safely sets the contents of the specified filepath to the specified value, then resets it to the original value upon test closure
func SetFileContentsAndPermissions ¶
SetFileContentsAndPermissions safely sets the contents of the specified filepath to the specified value and FileMode, then resets it to the original value upon test closure
Types ¶
type ErrorCache ¶
type ErrorCache struct {
Error error
}
ErrorCache is a struct that can be used to get at the error that is emitted by test assertions when passing it instead ot *testing.T
func (*ErrorCache) Errorf ¶
func (ec *ErrorCache) Errorf(format string, args ...interface{})
Errorf records the given formatted string as an erro
type GivenStatement ¶
type GivenStatement struct {
// contains filtered or unexported fields
}
GivenStatement is used to set up unit test preconditions
func Given ¶
func Given(description string, setup func()) GivenStatement
Given starts the test with the first precondition
func (GivenStatement) Branch ¶
func (g GivenStatement) Branch(runners ...Runner) Runner
Branch allows test branching by adding multiple sub-statements after a Given
func (GivenStatement) Given ¶
func (g GivenStatement) Given(description string, setup func()) GivenStatement
Given adds an additional precondition
func (GivenStatement) Given2 ¶
func (g GivenStatement) Given2(g2 GivenStatement) GivenStatement
Given2 allows the usage of a previously defined Given statement
func (GivenStatement) When ¶
func (g GivenStatement) When(description string, setup func()) WhenStatement
When adds a trigger to the test path
func (GivenStatement) When2 ¶
func (g GivenStatement) When2(w WhenStatement) WhenStatement
When2 allows the usage of a previously defined When statement
type Runner ¶
Runner combines ThenStatement and ThenStatements, this should not be implemented outside of this package!
type TestCases ¶
type TestCases[T any] []T
TestCases define alternative test setups that should all be tested
func AsTestCases ¶
AsTestCases is defined for convenience of casting a slice to TestCases
type ThenStatement ¶
type ThenStatement struct {
// contains filtered or unexported fields
}
ThenStatement is used to define test assertions
func Then ¶
func Then(description string, setup func(t *testing.T)) ThenStatement
Then is an independent outcome check that can be used to start a statement in a Branch
func (ThenStatement) Run ¶
func (then ThenStatement) Run(t *testing.T, repeats ...int) bool
Run executes all defined test paths. Optionally, each path is repeated a given number of times
func (ThenStatement) Then ¶
func (then ThenStatement) Then(description string, execution func(t *testing.T)) ThenStatement
Then adds an outcome check to the test path
func (ThenStatement) Then2 ¶
func (then ThenStatement) Then2(then2 ThenStatement) ThenStatement
Then2 allows the use of a previously defined Then statement
type ThenStatements ¶
type ThenStatements []ThenStatement
ThenStatements is used as an alias for multiple ThenStatement
type WhenStatement ¶
type WhenStatement struct {
// contains filtered or unexported fields
}
WhenStatement is used to define conditions under test
func When ¶
func When(description string, setup func()) WhenStatement
When is an independent trigger that can be used to start a statement in a Branch
func (WhenStatement) Branch ¶
func (w WhenStatement) Branch(runners ...Runner) Runner
Branch allows test branching by adding multiple sub-statements after a When
func (WhenStatement) Then ¶
func (w WhenStatement) Then(description string, execution func(t *testing.T)) ThenStatement
Then adds an outcome check to the test path
func (WhenStatement) Then2 ¶
func (w WhenStatement) Then2(then ThenStatement) ThenStatement
Then2 allows the use of a previously defined Then statement
func (WhenStatement) When ¶
func (w WhenStatement) When(description string, setup func()) WhenStatement
When adds a trigger to the test path
func (WhenStatement) When2 ¶
func (w WhenStatement) When2(w2 WhenStatement) WhenStatement
When2 allows the usage of a previously defined When statement