require

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package require provides assertion functions that wrap the functions from the `is` package. Unlike `is`, functions in `require` call t.FailNow() upon failure, immediately stopping the current test.

This is useful when a test cannot proceed meaningfully after a specific assertion fails.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(t testingT, collection any, element any, msgAndArgs ...any)

Contains requires that the specified list(array, slice...) contains the specified element.

func ContainsKey

func ContainsKey[K comparable, V any](t testingT, m map[K]V, key K, msgAndArgs ...any)

ContainsKey requires that the specified map contains the specified key.

func ElementsMatch

func ElementsMatch[T comparable](t testingT, listA []T, listB []T, msgAndArgs ...any)

ElementsMatch requires that the specified lists or maps contain the same elements in any order.

func Empty

func Empty(t testingT, data any, msgAndArgs ...any)

Empty requires that the specified object is empty. Objects considered empty are nil, "", false, 0, or a channel, slice, array or map with len == 0.

func Equal

func Equal[T any](t testingT, got T, want T, msgAndArgs ...any)

Equal requires that the two objects are equal.

func Error

func Error(t testingT, got error, msgAndArgs ...any)

Error requires that the specified err is not nil.

func ErrorAs

func ErrorAs(t testingT, got error, targetPtr any, msgAndArgs ...any)

ErrorAs requires that the specified error is assignable to the target.

func ErrorIs

func ErrorIs(t testingT, got error, target error, msgAndArgs ...any)

ErrorIs requires that the specified error is assignable to the target.

func False

func False(t testingT, value bool, msgAndArgs ...any)

False requires that the specified value is false.

func Greater

func Greater[T cmp.Ordered](t testingT, got T, threshold T, msgAndArgs ...any)

Greater requires that the first element is greater than the second.

func GreaterOrEqual

func GreaterOrEqual[T cmp.Ordered](t testingT, got T, threshold T, msgAndArgs ...any)

GreaterOrEqual requires that the first element is greater than or equal to the second.

func InDelta

func InDelta[T ~float32 | ~float64](t testingT, got T, want T, delta T, msgAndArgs ...any)

InDelta requires that the specified values are within the delta of each other.

func Len

func Len(t testingT, data any, expectedLen int, msgAndArgs ...any)

Len requires that the specified object has the specified length. Len also fails if the object has a type that len() not accept.

func Less

func Less[T cmp.Ordered](t testingT, got T, threshold T, msgAndArgs ...any)

Less requires that the first element is less than the second.

func LessOrEqual

func LessOrEqual[T cmp.Ordered](t testingT, got T, threshold T, msgAndArgs ...any)

LessOrEqual requires that the first element is less than or equal to the second.

func Negative

func Negative[T cmp.Ordered](t testingT, got T, msgAndArgs ...any)

Negative requires that the specified value is negative.

func Nil

func Nil(t testingT, data any, msgAndArgs ...any)

Nil requires that the specified object is nil.

func NoError

func NoError(t testingT, got error, msgAndArgs ...any)

NoError requires that the specified err is nil.

func NotContains

func NotContains(t testingT, collection any, element any, msgAndArgs ...any)

NotContains requires that the specified list(array, slice...) does not contain the specified element.

func NotContainsKey

func NotContainsKey[K comparable, V any](t testingT, m map[K]V, key K, msgAndArgs ...any)

NotContainsKey requires that the specified map does not contain the specified key.

func NotEmpty

func NotEmpty(t testingT, data any, msgAndArgs ...any)

NotEmpty requires that the specified object is not empty. Objects considered empty are nil, "", false, 0, or a channel, slice, array or map with len == 0.

func NotEqual

func NotEqual[T any](t testingT, got T, want T, msgAndArgs ...any)

NotEqual requires that the specified values are not equal.

func NotInDelta

func NotInDelta[T ~float32 | ~float64](t testingT, got T, want T, delta T, msgAndArgs ...any)

NotInDelta requires that the specified values are not within the delta of each other. It fails if |got - want| <= |delta|.

func NotNil

func NotNil(t testingT, data any, msgAndArgs ...any)

NotNil requires that the specified object is not nil.

func NotPanics

func NotPanics(t testingT, f func(), msgAndArgs ...any)

NotPanics requires that the code inside the specified PanicTestFunc does not panic.

func NotZero

func NotZero(t testingT, data any, msgAndArgs ...any)

NotZero requires that the specified value is not the zero value for its type.

func Panics

func Panics(t testingT, f func(), msgAndArgs ...any) (didPanic bool, panicValue any)

Panics requires that the code inside the specified PanicTestFunc panics.

func Positive

func Positive[T cmp.Ordered](t testingT, got T, msgAndArgs ...any)

Positive requires that the specified value is positive.

func TimeAfter

func TimeAfter(t testingT, got, threshold time.Time, msgAndArgs ...any)

TimeAfter requires that a time is after a threshold time

func TimeBefore

func TimeBefore(t testingT, got, threshold time.Time, msgAndArgs ...any)

TimeBefore requires that a time is before a threshold time

func TimeEqual

func TimeEqual(t testingT, got, want time.Time, msgAndArgs ...any)

TimeEqual requires that two times represent the same instant

func TimeEqualWithPrecision

func TimeEqualWithPrecision(t testingT, got, want time.Time, precision time.Duration, msgAndArgs ...any)

TimeEqualWithPrecision requires that two times are equal within a certain precision

func True

func True(t testingT, value bool, msgAndArgs ...any)

True requires that the specified value is true.

func WithinDuration

func WithinDuration(t testingT, got, want time.Time, delta time.Duration, msgAndArgs ...any)

WithinDuration requires that two times are within a certain duration of each other

func WithinTime

func WithinTime(t testingT, got time.Time, start, end time.Time, msgAndArgs ...any)

WithinTime requires that a time is within a given time window

func Zero

func Zero(t testingT, data any, msgAndArgs ...any)

Zero requires that the specified value is the zero value for its type.

Types

This section is empty.

Jump to

Keyboard shortcuts

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