assert

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmpIgnoreTimes added in v0.7.6

func CmpIgnoreTimes() cmp.Option

CmpIgnoreTimes is a cmp.Option that ignores BaseModel.Created, BaseModel.Updated, and BaseModel.Version This is useful if you want to display a diff without times (eg. `assert.Errorf("diff: %s", cmp.Diff(got, want, IgnoreTimes()))“)

func Contains

func Contains(t testing.TB, body, substr string, opts ...Option) bool

Contains asserts that one string contains another

func Equal

func Equal(t testing.TB, got, want interface{}, opts ...Option) bool

Equal asserts two objects are equal

func ErrorIs

func ErrorIs(t testing.TB, got, expected error, opts ...Option)

ErrorIs asserts that error is not nil and it matches the expected error

func Fail

func Fail(t testing.TB, fmt string, args ...interface{})

Fail marks the test as failed and stops execution

func FailContinue added in v0.8.0

func FailContinue(t testing.TB, fmt string, args ...interface{})

FailContinue marks the test as failed, but continues execution

func False

func False(t testing.TB, got bool, opts ...Option) bool

False is a shortcut for Equals(false)

func HTTPError added in v1.1.0

func HTTPError(t *testing.T, err error, code int)

HTTPError asserts that an error is an HTTP error with the given status code

func IsNil

func IsNil(t testing.TB, got interface{}, opts ...Option) bool

IsNil is a shortcut for Equals(nil)

func NoErr

func NoErr(t testing.TB, err error, opts ...Option)

NoErr is a shortcut for Nil(..., assert.Must())

func NotEqual

func NotEqual(t testing.TB, got, want interface{}, opts ...Option) bool

NotEqual asserts two objects are not equal

func NotNil

func NotNil(t testing.TB, got interface{}, opts ...Option) bool

NotNil is a shortcut for !Equals(nil)

func True

func True(t testing.TB, got bool, opts ...Option) bool

True is a shortcut for Equals(true)

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option defines a way to modify assert behavior

func CmpOpt

func CmpOpt(o cmp.Option) Option

CmpOpt adds a cmp.Option from the underlying lib Useful for things like .IgnoreUnexported

func Diff

func Diff() Option

Diff prints a diff between got & want on failure

func Errorf

func Errorf(msg string, args ...interface{}) Option

Errorf adds a more specific message to the failure

func IgnoreTimes added in v0.7.6

func IgnoreTimes() Option

IgnoreTimes ignores BaseModel.Created, BaseModel.Updated, and BaseModel.Version for cmp operations This is a helper to pass directly into eg. `assert.Equal`

func Must

func Must() Option

Must stops the test if this assert fails Useful if you're just going to run into eg. a nil pointer deref next

Jump to

Keyboard shortcuts

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