Documentation ¶
Index ¶
- func IfElse[V any](isTrue bool, valueIfTrue, valueIfFalse V) V
- func NonBlockingSend[V any](ch chan<- V, value V) bool
- func RequireNoMoreValues[V any](t TestContext, ch <-chan V, timeout time.Duration)
- func RequireNoMoreValuesWithMessage[V any](t TestContext, ch <-chan V, timeout time.Duration, msgFormat string, ...)
- func RequireValue[V any](t TestContext, ch <-chan V, timeout time.Duration) V
- func RequireValueWithMessage[V any](t TestContext, ch <-chan V, timeout time.Duration, msgFormat string, ...) V
- func SliceContains[V comparable](value V, slice []V) bool
- func TryReceive[V any](ch <-chan V, timeout time.Duration) opt.Maybe[V]
- type TestContext
- type TestRecorder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NonBlockingSend ¶
NonBlockingSend is a shortcut for using select to do a non-blocking send. It returns true on success or false if the channel was full.
func RequireNoMoreValues ¶
func RequireNoMoreValues[V any](t TestContext, ch <-chan V, timeout time.Duration)
RequireNoMoreValues tries to receive a value within the given timeout, and causes the test to fail and terminate immediately if a value was received.
func RequireNoMoreValuesWithMessage ¶
func RequireNoMoreValuesWithMessage[V any]( t TestContext, ch <-chan V, timeout time.Duration, msgFormat string, msgArgs ...interface{}, )
RequireNoMoreValuesWithMessage is the same as RequireNoMoreValues, but allows customization of the failure message.
func RequireValue ¶
func RequireValue[V any](t TestContext, ch <-chan V, timeout time.Duration) V
RequireValue tries to receive a value and returns it if successful, or causes the test to fail and terminate immediately if it timed out.
func RequireValueWithMessage ¶
func RequireValueWithMessage[V any]( t TestContext, ch <-chan V, timeout time.Duration, msgFormat string, msgArgs ...interface{}, ) V
RequireValueWithMessage is the same as RequireValue, but allows customization of the failure message.
func SliceContains ¶
func SliceContains[V comparable](value V, slice []V) bool
SliceContains returns true if and only if the slice has an element that equals the value.
Types ¶
type TestContext ¶
type TestContext interface { Errorf(msgFormat string, msgArgs ...interface{}) FailNow() }
TestContext is a minimal interface for types like *testing.T and *ldtest.T representing a test that can fail. Functions can use this to avoid specific dependencies on those packages.
type TestRecorder ¶
TestRecorder is a stub implementation of TestContext for testing test logic.
func (*TestRecorder) Err ¶
func (t *TestRecorder) Err() error
Err returns an error whose message is a concatenation of all error messages so far, or nil if none.
func (*TestRecorder) Errorf ¶
func (t *TestRecorder) Errorf(format string, args ...interface{})
Errorf records an error message.
func (*TestRecorder) FailNow ¶
func (t *TestRecorder) FailNow()
FailNow simulates a condition where the test is supposed to immediately terminate. It sets t.Terminated to true, and then does a panic(t) if and only if t.PanicOnTerminate is true.