assert

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Approximately added in v0.3.0

func Approximately(t *testing.T, expected time.Duration, actual time.Duration, delta time.Duration, prefixes ...string)

Approximately asserts actual duration is approximately(within delta difference) equal to expected duration.

func ApproximatelyTime added in v0.11.0

func ApproximatelyTime(t *testing.T, expected time.Time, actual time.Time, delta time.Duration, prefixes ...string)

ApproximatelyTime asserts actual time.Time is approximately(within delta difference) equal to expected time.Time.

func ElementsMatch

func ElementsMatch[T any](t *testing.T, arrA, arrB []T, prefixes ...string)

ElementsMatch asserts both slices have the same amount and equal elements. Any extra items will be listed in error log.

func Equal

func Equal(t *testing.T, expected interface{}, actual interface{}, prefixes ...string)

Equal asserts expected and actual values are equal using deep equal from reflection.

func Error

func Error(t *testing.T, err error, prefixes ...string)

func ErrorIs

func ErrorIs(t *testing.T, err error, target error, prefixes ...string)

ErrorIs asserts whether error in err's chain matches target.

func ErrorType

func ErrorType(t *testing.T, err error, target error, prefixes ...string)

ErrorType matches just type of error.

func ErrorWith

func ErrorWith(t *testing.T, err error, content string, prefixes ...string)

ErrorWith asserts err does contain target content within error string representation.

func ExpectCall added in v0.8.0

func ExpectCall(fn any)

ExpectCall panics with unexpected call message for caller name if fn is nil. If fn is not a func then it will panic with invalid parameter message. Standard way to call this is:

func (m MyMock) Do(key string) error {
	assert.ExpectCall(m.OnDo) // if m.OnDo is nil - it will panic with accurate message
	return m.OnDo(key)
}

func MapHas

func MapHas[K comparable, V any](t *testing.T, m map[K]V, key K, val V, prefixes ...string)

MapHas asserts that map contains specified key with equal value.

func MapMatch

func MapMatch[K comparable, V any](t *testing.T, mapA, mapB map[K]V, prefixes ...string)

MapMatch asserts all keys and corresponding values are applied to both map.

func NilError

func NilError(t *testing.T, err error, prefixes ...string)

func NotEqual

func NotEqual(t *testing.T, expected interface{}, actual interface{}, prefixes ...string)

NotEqual asserts expected and actual values are not equal using equal operator.

func NotNil

func NotNil(t *testing.T, val interface{}, prefixes ...string)

Types

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

func Count

func Count(t *testing.T, n int, prefixes ...string) *Counter

Count returns a Counter with expected n count to be asserted. Use Inc() to mark a call. Assert() will be called on test cleanup, so it's not necessary to call it manually but recommended due to convention to not hide any test side effects.

func (*Counter) Assert

func (c *Counter) Assert(t *testing.T, prefixes ...string)

Assert checks for count expectation.

func (*Counter) AtLeast added in v0.4.0

func (c *Counter) AtLeast() *Counter

AtLeast marks counter to assert for at least count instead exact count and returns self.

func (*Counter) Inc

func (c *Counter) Inc()

Inc marks a single call to the function. This is thread safe operation.

type ErrorFunc

type ErrorFunc func(t *testing.T, err error)

type ResultErrorFunc

type ResultErrorFunc[T any] func(t *testing.T, result T, err error)

Jump to

Keyboard shortcuts

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