require

package
v2.11.6 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package require implements test assertions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ElementsEqual

func ElementsEqual(tb testing.TB, expecteds interface{}, actuals interface{}, msgAndArgs ...interface{})

ElementsEqual checks that the elements of the slice "expecteds" are exactly the elements of the slice "actuals", ignoring order (i.e. setwise-equal, but respecting duplicates).

Note that if the elements of 'expecteds' and 'actuals' are pointers, ElementsEqual will unwrap the pointers before comparing them, so that the output of e.g. ListCommit(), which returns []*pfs.Commit can easily be verfied.

Also, treat 'nil' and the empty slice as equivalent, so that callers can pass 'nil' for 'expecteds'.

func ElementsEqualOrErr

func ElementsEqualOrErr(expecteds interface{}, actuals interface{}) error

ElementsEqualOrErr returns nil if the elements of the slice "expecteds" are exactly the elements of the slice "actuals", ignoring order (i.e. setwise-equal), and an error otherwise.

Unlike other require.* functions, this returns an error, so that if the caller is polling e.g. ListCommit or ListAdmins, they can wrap ElementsEqualOrErr in a retry loop.

Also, like ElementsEqual, treat 'nil' and the empty slice as equivalent (for convenience)

func ElementsEqualUnderFn

func ElementsEqualUnderFn(tb testing.TB, expecteds interface{}, actuals interface{}, f func(interface{}) interface{}, msgAndArgs ...interface{})

ElementsEqualUnderFn checks that the elements of the slice 'expecteds' are the same as the elements of the slice 'actuals' under 'f', ignoring order (i.e. 'expecteds' and 'map(f, actuals)' are setwise-equal, but respecting duplicates). This is useful for cases where ElementsEqual doesn't quite work, e.g. because the type in 'expecteds'/'actuals' contains a pointer, or 'actuals' contains superfluous data which you wish to discard.

Like ElementsEqual, treat 'nil' and the empty slice as equivalent (for convenience)

func Equal

func Equal(tb testing.TB, expected interface{}, actual interface{}, msgAndArgs ...interface{})

Equal checks the equality of two values

func EqualOneOf

func EqualOneOf(tb testing.TB, expecteds interface{}, actual interface{}, msgAndArgs ...interface{})

EqualOneOf checks if a value is equal to one of the elements of a slice. Note that if expecteds and actual are a slice of pointers and a pointer respectively, then the pointers are unwrapped before comparison (so this functions works for e.g. *pfs.Commit and []*pfs.Commit)

func EqualOrErr

func EqualOrErr(expected interface{}, actual interface{}) error

EqualOrErr checks equality of two values and returns an error if they're not equal

func ErrorContains

func ErrorContains(tb testing.TB, err error, contains string, msgAndArgs ...interface{})

ErrorContains checks that the error contains a specified substring.

func ErrorIs

func ErrorIs(tb testing.TB, err, target error, msgAndArgs ...interface{})

ErrorIs checks that the errors.Is returns true

func False

func False(tb testing.TB, value bool, msgAndArgs ...interface{})

False checks a value is false.

func ImagesEqual

func ImagesEqual(tb testing.TB, expecteds interface{}, actuals interface{}, f func(interface{}) interface{}, msgAndArgs ...interface{})

ImagesEqual is similar to 'ElementsEqualUnderFn', but it applies 'f' to both 'expecteds' and 'actuals'. This is useful for doing before/after comparisons. This can also compare 'T' and '*T' , but 'f' should expect interfaces wrapping the underlying types of 'expecteds' (e.g. if 'expecteds' has type []*T and 'actuals' has type []T, then 'f' should cast its argument to '*T')

Like ElementsEqual, treat 'nil' and the empty slice as equivalent (for convenience)

func Len

func Len(tb testing.TB, x interface{}, l int, msgAndArgs ...interface{})

Len asserts the the provided object x has length l ( len(x) == l )

func Matches

func Matches(tb testing.TB, expectedMatch string, actual string, msgAndArgs ...interface{})

Matches checks that a string matches a regular-expression.

func Nil

func Nil(tb testing.TB, object interface{}, msgAndArgs ...interface{})

Nil checks a value is nil.

func NoDiff added in v2.9.5

func NoDiff(tb testing.TB, expected any, actual any, opts []cmp.Option, msgAndArgs ...any)

NoDiff does a diff, and fails if there are differences. Use protocmp.Transform() to compare protos.

func NoError

func NoError(tb testing.TB, err error, msgAndArgs ...interface{})

NoError checks for no error.

func NoErrorWithinT

func NoErrorWithinT(tb testing.TB, t time.Duration, f func() error, msgAndArgs ...interface{})

NoErrorWithinT checks that 'f' finishes within time 't' and does not emit an error

func NoErrorWithinTRetry

func NoErrorWithinTRetry(tb testing.TB, t time.Duration, f func() error, msgAndArgs ...interface{})

NoErrorWithinTRetry checks that 'f' finishes within time 't' and does not emit an error. Unlike NoErrorWithinT if f does error, it will retry it. Uses an exponential backoff.

func NoErrorWithinTRetryConstant

func NoErrorWithinTRetryConstant(tb testing.TB, t time.Duration, f func() error, interval time.Duration, msgAndArgs ...interface{})

NoErrorWithinTRetryConstant checks that 'f' finishes within time 't' and does not emit an error. Will retry at a constant specified interval rather than using exponential backoff

func NoneEquals

func NoneEquals(tb testing.TB, expected interface{}, actuals interface{}, msgAndArgs ...interface{})

NoneEquals checks one element of a slice equals a value. Like EqualsOneOf, NoneEquals unwraps pointers.

func NoneMatch

func NoneMatch(tb testing.TB, shouldNotMatch string, actuals []string, msgAndArgs ...interface{})

NoneMatch checks whether any element of a slice matches a regular-expression and returns an error if a match is found.

func NotEqual

func NotEqual(tb testing.TB, expected interface{}, actual interface{}, msgAndArgs ...interface{})

NotEqual checks inequality of two values.

func NotMatch

func NotMatch(tb testing.TB, shouldNotMatch string, actual string, msgAndArgs ...interface{})

NotMatch checks whether actual matches a regular-expression and returns an error if a match is found.

func NotNil

func NotNil(tb testing.TB, object interface{}, msgAndArgs ...interface{})

NotNil checks a value is non-nil.

func OneOfEquals

func OneOfEquals(tb testing.TB, expected interface{}, actuals interface{}, msgAndArgs ...interface{})

OneOfEquals checks whether one element of a slice equals a value. Like EqualsOneOf, OneOfEquals unwraps pointers

func OneOfMatches

func OneOfMatches(tb testing.TB, expectedMatch string, actuals []string, msgAndArgs ...interface{})

OneOfMatches checks whether one element of a slice matches a regular-expression.

func True

func True(tb testing.TB, value bool, msgAndArgs ...interface{})

True checks a value is true.

func YesError

func YesError(tb testing.TB, err error, msgAndArgs ...interface{})

YesError checks for an error.

func YesPanic

func YesPanic(tb testing.TB, cb func(), msgAndArgs ...interface{})

YesPanic checks that the callback panics.

Types

This section is empty.

Jump to

Keyboard shortcuts

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