Documentation ¶
Overview ¶
Package require implements test assertions.
Index ¶
- func ElementsEqual(tb testing.TB, expecteds interface{}, actuals interface{}, ...)
- func ElementsEqualOrErr(expecteds interface{}, actuals interface{}) error
- func ElementsEqualUnderFn(tb testing.TB, expecteds interface{}, actuals interface{}, ...)
- func Equal(tb testing.TB, expected interface{}, actual interface{}, ...)
- func EqualOneOf(tb testing.TB, expecteds interface{}, actual interface{}, ...)
- func EqualOrErr(expected interface{}, actual interface{}) error
- func ErrorContains(tb testing.TB, err error, contains string, msgAndArgs ...interface{})
- func ErrorIs(tb testing.TB, err, target error, msgAndArgs ...interface{})
- func False(tb testing.TB, value bool, msgAndArgs ...interface{})
- func ImagesEqual(tb testing.TB, expecteds interface{}, actuals interface{}, ...)
- func Len(tb testing.TB, x interface{}, l int, msgAndArgs ...interface{})
- func Matches(tb testing.TB, expectedMatch string, actual string, msgAndArgs ...interface{})
- func Nil(tb testing.TB, object interface{}, msgAndArgs ...interface{})
- func NoDiff(tb testing.TB, expected any, actual any, opts []cmp.Option, msgAndArgs ...any)
- func NoError(tb testing.TB, err error, msgAndArgs ...interface{})
- func NoErrorWithinT(tb testing.TB, t time.Duration, f func() error, msgAndArgs ...interface{})
- func NoErrorWithinTRetry(tb testing.TB, t time.Duration, f func() error, msgAndArgs ...interface{})
- func NoErrorWithinTRetryConstant(tb testing.TB, t time.Duration, f func() error, interval time.Duration, ...)
- func NoneEquals(tb testing.TB, expected interface{}, actuals interface{}, ...)
- func NoneMatch(tb testing.TB, shouldNotMatch string, actuals []string, ...)
- func NotEqual(tb testing.TB, expected interface{}, actual interface{}, ...)
- func NotMatch(tb testing.TB, shouldNotMatch string, actual string, msgAndArgs ...interface{})
- func NotNil(tb testing.TB, object interface{}, msgAndArgs ...interface{})
- func OneOfEquals(tb testing.TB, expected interface{}, actuals interface{}, ...)
- func OneOfMatches(tb testing.TB, expectedMatch string, actuals []string, ...)
- func True(tb testing.TB, value bool, msgAndArgs ...interface{})
- func YesError(tb testing.TB, err error, msgAndArgs ...interface{})
- func YesPanic(tb testing.TB, cb func(), msgAndArgs ...interface{})
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 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 ¶
ErrorContains checks that the error contains a specified substring.
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 NoDiff ¶ added in v2.9.5
NoDiff does a diff, and fails if there are differences. Use protocmp.Transform() to compare protos.
func NoErrorWithinT ¶
NoErrorWithinT checks that 'f' finishes within time 't' and does not emit an error
func NoErrorWithinTRetry ¶
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 ¶
NoneMatch checks whether any element of a slice matches a regular-expression and returns an error if a match is found.
func NotMatch ¶
NotMatch checks whether actual matches a regular-expression and returns an error if a match is found.
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 ¶
OneOfMatches checks whether one element of a slice matches a regular-expression.
Types ¶
This section is empty.