assert

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 7 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 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 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.

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