Documentation
¶
Overview ¶
Package assert contains helpful assertion helpers. Under the hood it currently uses github.com/stretchr/testify/assert, but this might change in the future. In order to keep this transparent to the tests, unit tests should exclusively use this package. This also helps us keep track how often the individual assert functions are used and whether we can reduce the API surface of this package.
Index ¶
- Variables
- func AnyValue[T any](*testing.T, T) bool
- func CompareAllUnexported() cmp.Option
- func Empty[T any](t *testing.T, obj T) bool
- func Equal[T any](t TestingT, want T, got T, opts ...cmp.Option) bool
- func Is[T any](t TestingT, a any) (obj T)
- func Nil[T any](t *testing.T, obj T) bool
- func NotEqual[T any](t TestingT, want T, got T, opts ...cmp.Option) bool
- func NotNil[T any](t *testing.T, obj T) bool
- func Optional[T any](t *testing.T, want Want[T], got T) bool
- type ErrorAssertionFunc
- type TestingT
- type Want
- type WantErr
Constants ¶
This section is empty.
Variables ¶
var Contains = assert.Contains
var Error = assert.Error
var ErrorContains = assert.ErrorContains
var ErrorIs = assert.ErrorIs
var Fail = assert.Fail
var False = assert.False
var NoError = assert.NoError
var NotEmpty = assert.NotEmpty
var Same = assert.Same
var True = assert.True
Functions ¶
func CompareAllUnexported ¶
CompareAllUnexported is a cmp.Option that allows the introspection of all un-exported fields in order to use them in Equal or NotEqual.
func Equal ¶
Equal asserts that [got] and [want] are Equal. Under the hood, this uses the go-cmp package in combination with protocmp and also supplies a diff, in case the messages to do not match.
Note: By default the option protocmp.Transform() will be used. This can cause problems with structs that are NOT protobuf messages and contain un-exported fields. In this case, CompareAllUnexported can be used instead.
func Is ¶
Is asserts that a certain incoming object a (of type [any]) is of type T. It will return a type casted variant of that object in the return value obj, if it succeeded.
Types ¶
type ErrorAssertionFunc ¶
type ErrorAssertionFunc = assert.ErrorAssertionFunc