helpers

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTimeout = 20 * time.Second

DefaultTimeout is the default timeout given to test contexts.

View Source
var ErrChannelClosed = errors.New("channel was closed")
View Source
var ErrReadTimeout = errors.New("context timed out while reading channel")
View Source
var IgnoreUnexported = cmpopts.IgnoreUnexported

Functions

func AsCheckFunc

func AsCheckFunc[W any, G any](check func(W, G) error) func(W) CheckFunc[G]

AsCheckFunc transforms a basic want/got checker into a CheckFunc generator.

func DoesNotPanic

func DoesNotPanic(f func()) (err error)

func Equal

func Equal[T any](want, got T, opts ...cmp.Option) error

Equal returns an error if values are different.

func Equalf

func Equalf[T any](want, got T, msg string, args ...any) error

Equalf returns an error if values are not "DeepEqual".

func Expect

func Expect(t *testing.T, errs ...error)

Expect allows to chain helpers in imperative-style testing

func HasNoError

func HasNoError[T any](_ T, err error) error

HasNoError is a CheckFunc that asserts the absence of an error.

func IgnoreFields

func IgnoreFields[T any](fields ...string) cmp.Option

func IsEmptySlice

func IsEmptySlice[T any](slice []T) error

func IsError

func IsError(want, got error) error

IsError checks that the returned error (got) is the one expected (want). If want is nil, it behaves the same as NoError.

func IsErrorf

func IsErrorf(want, got error, msg string, args ...any) error

IsErrorf checks that the returned error is the expected one.

func IsNilPointer

func IsNilPointer[T any](ptr *T) error

IsNilPointer returns an error if given pointer is not nil.

func IsNilPointerf

func IsNilPointerf[T any](ptr *T, msg string, args ...any) error

IsNilPointerf returns an error if given pointer is not nil.

func IsNotEmptySlice

func IsNotEmptySlice[T any](slice []T) error

func IsNotNilPointer

func IsNotNilPointer[T any](ptr *T) error

IsNotNilPointer returns an error if given pointer is nil.

func IsNotNilPointerf

func IsNotNilPointerf[T any](ptr *T, msg string, args ...any) error

IsNotNilPointer returns an error if given pointer is nil.

func IsNotZero

func IsNotZero[T any](have T, opts ...cmp.Option) error

IsNotZero returns an error if the value is not a zero value.

func IsNotZerof

func IsNotZerof[T any](have T, msg string, args ...any) error

IsNotZerof returns an error with a custom message if the value is not a zero value.

func IsSamePointer

func IsSamePointer[T any](want, got *T) error

func IsSamePointerf

func IsSamePointerf[T any](want, got *T, msg string, args ...any) error

func IsZero

func IsZero[T any](obj T) error

func NewTestContext

func NewTestContext() (context.Context, context.CancelFunc)

NewTestContext returns a context with a sensible default timeout for tests.

func NoError

func NoError(err error) error

NoError checks that the returned error is nil.

func NoErrorf

func NoErrorf(err error, msg string, args ...any) error

NoErrorf checks that the returned error is nil.

func NotEqual

func NotEqual[T any](want, got T, opts ...cmp.Option) error

NotEqual returns an error if values are the same.

func NotEqualf

func NotEqualf[T any](want, got T, msg string, args ...any) error

NotEqualf returns an error if values are the same.

func PointerTo

func PointerTo[T any](obj T) *T

func ReadChannel

func ReadChannel[T any](ctx context.Context, ch <-chan T) (T, error)

func Require

func Require(t *testing.T, errs ...error)

Require allows to chain helpers in imperative-style testing

func ShouldPanic

func ShouldPanic(f func()) error

ShouldPanic returns an error if given function does not panic when called.

func SliceContains

func SliceContains[T comparable](want T, slice []T) error

func SliceDoesNotContain

func SliceDoesNotContain[T comparable](want T, slice []T) error

func SliceHasLength

func SliceHasLength[T any](want int, slice []T) error

func TestContext

func TestContext(timeout time.Duration) (context.Context, context.CancelFunc)

TestContext is a short wrapper around context.WithTimeout.

Types

type CheckFunc

type CheckFunc[T any] func(T, error) error

func CheckAll

func CheckAll[T any](checks ...CheckFunc[T]) CheckFunc[T]

func HasError

func HasError[T any](want error) CheckFunc[T]

Jump to

Keyboard shortcuts

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