Documentation ¶
Index ¶
- Variables
- func WithTestContext(ctx context.Context) stdlib.Option[*TestConfig]
- func WithTestEnv(env map[string]string) stdlib.Option[*TestConfig]
- func WithTestLogf(log Logf) stdlib.Option[*TestConfig]
- func WithTestMaxCount(maxCount int) stdlib.Option[*TestConfig]
- func WithTestMaxCountScale(maxCountScale float64) stdlib.Option[*TestConfig]
- func WithTestParallel(parallel bool) stdlib.Option[*TestConfig]
- func WithTestPrecondition(preconditions ...TestPrecondition) stdlib.Option[*TestConfig]
- func WithTestRand(r *rand.Rand) stdlib.Option[*TestConfig]
- func WithTestSkip(skip string) stdlib.Option[*TestConfig]
- func WithTestTimeout(to time.Duration) stdlib.Option[*TestConfig]
- type Assert
- func (a *Assert) Equal(got, want any) bool
- func (a *Assert) EqualComparer(got, want any, cmp Comparer) bool
- func (a *Assert) EqualError(got, want error) bool
- func (a *Assert) EqualFloat(got, want, epsilon float64) bool
- func (a *Assert) EqualPointer(got, want any) bool
- func (a *Assert) EqualType(got, want any) bool
- func (a *Assert) False(condition bool, format string, args ...any) bool
- func (a *Assert) Match(got, wantPattern string) bool
- func (a *Assert) NotEqual(got, want any) bool
- func (a *Assert) NotOK(err error) bool
- func (a *Assert) OK(err error) bool
- func (a *Assert) Panic(got func()) bool
- func (a *Assert) True(condition bool, format string, args ...any) bool
- type Asserter
- type Check
- type Checker
- type Comparer
- type Logf
- type Table
- type Test
- func BenchmarkTest(t *testing.B, options ...stdlib.Option[*TestConfig]) *Test
- func FuzzTest(t *testing.F, options ...stdlib.Option[*TestConfig]) *Test
- func IntegrationTest(t *testing.T, options ...stdlib.Option[*TestConfig]) *Test
- func NewTest(t testing.TB, options ...stdlib.Option[*TestConfig]) *Test
- func PropertyTest(t testing.TB, options ...stdlib.Option[*TestConfig]) *Test
- func UnitTest(t testing.TB, options ...stdlib.Option[*TestConfig]) *Test
- type TestConfig
- type TestFunc
- type TestPrecondition
- type Testcase
Constants ¶
This section is empty.
Variables ¶
var ErrTestParallelWithSetEnv = stdlib.Error{ Code: "parallel_with_setenv", Message: "test cannot be parallel and also modify environment variables", Namespace: stdlib.ErrorNamespaceDefault, }
ErrTestParallelWithSetEnv is returned when attempting to create a parallel test that overrides process environment variables.
Functions ¶
func WithTestContext ¶ added in v1.8.0
func WithTestContext(ctx context.Context) stdlib.Option[*TestConfig]
WithTestContext sets the config ctx.
func WithTestEnv ¶ added in v1.8.0
func WithTestEnv(env map[string]string) stdlib.Option[*TestConfig]
WithTestEnv sets the config env.
func WithTestLogf ¶
func WithTestLogf(log Logf) stdlib.Option[*TestConfig]
WithTestLogf sets the config logf.
func WithTestMaxCount ¶
func WithTestMaxCount(maxCount int) stdlib.Option[*TestConfig]
WithTestMaxCount sets the config property testing max count.
func WithTestMaxCountScale ¶
func WithTestMaxCountScale(maxCountScale float64) stdlib.Option[*TestConfig]
WithTestMaxCountScale sets the config property testing max count scale.
func WithTestParallel ¶
func WithTestParallel(parallel bool) stdlib.Option[*TestConfig]
WithTestParallel sets the config parallel.
func WithTestPrecondition ¶
func WithTestPrecondition(preconditions ...TestPrecondition) stdlib.Option[*TestConfig]
WithTestPrecondition sets the config preconditions.
func WithTestRand ¶
func WithTestRand(r *rand.Rand) stdlib.Option[*TestConfig]
WithTestRand sets the config rand number generator.
func WithTestSkip ¶ added in v1.41.0
func WithTestSkip(skip string) stdlib.Option[*TestConfig]
WithTestSkip sets the config skip reason.
func WithTestTimeout ¶ added in v1.8.0
func WithTestTimeout(to time.Duration) stdlib.Option[*TestConfig]
WithTestTimeout sets the config timeout.
Types ¶
type Assert ¶
type Assert struct {
// contains filtered or unexported fields
}
Assert implements helpers for common assertion patterns.
func (*Assert) Equal ¶
Equal fails the test if 'got' is not equal to 'want' using reflect.DeepEqual.
func (*Assert) EqualComparer ¶ added in v1.16.0
EqualComparer fails the test if the comparer is not true for the given values.
func (*Assert) EqualError ¶ added in v1.4.1
EqualError fails the test if 'got' is not equal to 'want' for errors.
func (*Assert) EqualFloat ¶ added in v1.40.0
EqualFloat fails the test if 'got' is not equal to 'want' for float64 values.
func (*Assert) EqualPointer ¶ added in v1.4.1
EqualPointer fails the test if 'got' is not equal to 'want' for pointers.
func (*Assert) EqualType ¶ added in v1.5.0
EqualType fails the test if 'got' is not equal to 'want' for concrete types.
func (*Assert) NotEqual ¶ added in v1.9.0
NotEqual fails the test if 'got' is equal to 'want' using reflect.DeepEqual.
type Asserter ¶
type Asserter interface { True(condition bool, format string, args ...any) bool False(condition bool, format string, args ...any) bool OK(err error) bool NotOK(err error) bool Match(got, want string) bool NotEqual(got, want any) bool Equal(got, want any) bool EqualPointer(got, want any) bool EqualError(got, want error) bool EqualType(got, want any) bool EqualComparer(got, want any, cmp Comparer) bool EqualFloat(got, want, epsilon float64) bool Panic(got func()) bool }
Asserter defines common test assertions.
type Check ¶
type Check struct {
// contains filtered or unexported fields
}
Check implements property testing via the "testing/quick" package.
func (*Check) CheckEqual ¶
CheckEqual fails the test if the check function returns false.
type Comparer ¶ added in v1.16.0
Comparer is a function that compares two values of any type and returns true if they are "equal".
type Logf ¶
Logf is the func called when a boolean condition is not met as part of an assertion. It's responsible for generating output to a user indicating the test failure and either allowing the test to continue or immediately stop execution.
type Test ¶
type Test struct { // TB is the golang 'testing' implementation for (T, B, F) tests. testing.TB // Asserter handles common test assertions. Asserter // Checker handles property tests. Checker // Config stores configuration specific to an individual test. Config *TestConfig }
Test merges the stdlib 'testing.TB' with our test helpers into a single implementation.
By using this 'Test' instead of the `testing` structs (T, B, F) we can automatically handle many common assertion patterns and preconditions for different test types (functional, fuzz, or integration).
func BenchmarkTest ¶
BenchmarkTest creates a new *Benchmark configured for running only "benchmark" tests when the BENCHMARK_TEST environment variable is set.
func FuzzTest ¶
FuzzTest creates a new *Benchmark configured for running only "fuzz" tests when the FUZZ_TEST environment variable is set.
func IntegrationTest ¶
IntegrationTest creates a new *Test configured for running only "integration" tests when the INTEGRATION_TEST environment variable is set.
func PropertyTest ¶
PropertyTest creates a new *Test configured for running only "property" tests.
type TestConfig ¶
type TestConfig struct { // Context is context for an individual test. Context context.Context // Env contains key/value pairs to be set with 'os.SetEnv' for the scope of the test. Env map[string]string // Logf is called when condition of test assertion is not met. Logf Logf // Parallel enables/disables Parallel test execution. Parallel bool // Preconditions are called before test execution to determine if test should // be skipped and the reason for it. Preconditions []TestPrecondition // QuickConfig modifies of how quick test (property tests) are executed. QuickConfig *quick.Config // Skip test for this reason. Skip string // Timeout is timeout duration for test execution. Timeout time.Duration }
TestConfig defines config options for test.
func NewTestConfig ¶
func NewTestConfig(options ...stdlib.Option[*TestConfig]) (*TestConfig, error)
NewTestConfig creates a new *TestConfig for the given functional opts and sane defaults.
type TestFunc ¶
TestFunc is a function that executes a single test for the given testcase.
Note: The benefit of passing in an isolated function for the test is that we can avoid issues with closures when t.Run(...) is called in parallel with the testcase.
type TestPrecondition ¶
TestPrecondition is a func called prior to test execution to determine if the test should be skipped and the reason for it.
func TestPreconditionEnvVarSet ¶ added in v1.11.0
func TestPreconditionEnvVarSet(name string) TestPrecondition
TestPreconditionEnvVarSet returns true if the given environment variable name is present.
type Testcase ¶
type Testcase[TGot any, TWant any] struct { // Got stores inputs for the testcase. Got TGot // Want stores the expectations for the testcase. Want TWant // WantErr stores the optional error expectation for the testcase. WantErr error // WantPanic store expectation for the test case to cause a panic. WantPanic bool // Options are custom options for test execution specific to this case. Options []stdlib.Option[*TestConfig] }
Testcase encapsulates the inputs and expectations of a single testcase.