assert

package
v2.0.0-alpha.4 Latest Latest
Warning

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

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

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

Constants

This section is empty.

Variables

View Source
var Contains = assert.Contains
View Source
var Error = assert.Error
View Source
var ErrorContains = assert.ErrorContains
View Source
var ErrorIs = assert.ErrorIs
View Source
var Fail = assert.Fail
View Source
var False = assert.False
View Source
var NoError = assert.NoError
View Source
var NotEmpty = assert.NotEmpty
View Source
var Same = assert.Same
View Source
var True = assert.True

Functions

func AnyValue

func AnyValue[T any](*testing.T, T) bool

AnyValue is a Want that accepts any value of T.

func CompareAllUnexported

func CompareAllUnexported() cmp.Option

CompareAllUnexported is a cmp.Option that allows the introspection of all un-exported fields in order to use them in Equal or NotEqual.

func Empty

func Empty[T any](t *testing.T, obj T) bool

func Equal

func Equal[T any](t TestingT, want T, got T, opts ...cmp.Option) bool

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

func Is[T any](t TestingT, a any) (obj T)

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.

func Nil

func Nil[T any](t *testing.T, obj T) bool

func NotEqual

func NotEqual[T any](t TestingT, want T, got T, opts ...cmp.Option) bool

NotEqual is similar to Equal, but inverse.

func NotNil

func NotNil[T any](t *testing.T, obj T) bool

func Optional

func Optional[T any](t *testing.T, want Want[T], got T) bool

Optional asserts the [want] function, if it is not nil. Otherwise, the assertion is ignored. This is helpful if an extra Want func is specified only for a select sub-set of table tests.

Types

type ErrorAssertionFunc

type ErrorAssertionFunc = assert.ErrorAssertionFunc

type TestingT

type TestingT = assert.TestingT

type Want

type Want[T any] func(t *testing.T, got T) bool

Want is a function type that can hold asserts in order to check the validity of "got".

type WantErr

type WantErr func(t *testing.T, err error) bool

WantErr is a function type that can hold asserts in order to check the error of "err".

Jump to

Keyboard shortcuts

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