helpers

package
v2.0.0-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IfElse

func IfElse[V any](isTrue bool, valueIfTrue, valueIfFalse V) V

IfElse returns valueIfTrue or valueIfFalse depending on isTrue.

func NonBlockingSend

func NonBlockingSend[V any](ch chan<- V, value V) bool

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.

func TryReceive

func TryReceive[V any](ch <-chan V, timeout time.Duration) opt.Maybe[V]

TryReceive is a shortcut for using select to do a receive with timeout. It returns a Maybe that has a value if one was available, or no value if it timed out.

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

type TestRecorder struct {
	Errors           []string
	Terminated       bool
	PanicOnTerminate bool
}

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.

Jump to

Keyboard shortcuts

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