Documentation ¶
Overview ¶
Package assert provides some tool functions for use with the Go testing.
inspired the package: github.com/stretchr/testify/assert
Index ¶
- Variables
- func Contains(t TestingT, src, elem any, fmtAndArgs ...any) bool
- func ContainsKey(t TestingT, mp, key any, fmtAndArgs ...any) bool
- func ContainsKeys(t TestingT, mp any, keys any, fmtAndArgs ...any) bool
- func DisableColor()
- func Empty(t TestingT, give any, fmtAndArgs ...any) bool
- func Eq(t TestingT, want, give any, fmtAndArgs ...any) bool
- func Equal(t TestingT, want, give any, fmtAndArgs ...any) bool
- func Err(t TestingT, err error, fmtAndArgs ...any) bool
- func ErrIs(t TestingT, err, wantErr error, fmtAndArgs ...any) bool
- func ErrMsg(t TestingT, err error, wantMsg string, fmtAndArgs ...any) bool
- func ErrSubMsg(t TestingT, err error, subMsg string, fmtAndArgs ...any) bool
- func Error(t TestingT, err error, fmtAndArgs ...any) bool
- func Fail(t TestingT, failMsg string, fmtAndArgs ...any) bool
- func FailNow(t TestingT, failMsg string, fmtAndArgs ...any) bool
- func False(t TestingT, give bool, fmtAndArgs ...any) bool
- func Gt(t TestingT, give, min int, fmtAndArgs ...any) bool
- func HideFullPath()
- func IsKind(t TestingT, wantKind reflect.Kind, give any, fmtAndArgs ...any) bool
- func IsType(t TestingT, wantType, give any, fmtAndArgs ...any) bool
- func Len(t TestingT, give any, wantLn int, fmtAndArgs ...any) bool
- func LenGt(t TestingT, give any, minLn int, fmtAndArgs ...any) bool
- func Lt(t TestingT, give, max int, fmtAndArgs ...any) bool
- func Neq(t TestingT, want, give any, fmtAndArgs ...any) bool
- func Nil(t TestingT, give any, fmtAndArgs ...any) bool
- func NoErr(t TestingT, err error, fmtAndArgs ...any) bool
- func NoError(t TestingT, err error, fmtAndArgs ...any) bool
- func NotContains(t TestingT, src, elem any, fmtAndArgs ...any) bool
- func NotEmpty(t TestingT, give any, fmtAndArgs ...any) bool
- func NotEq(t TestingT, want, give any, fmtAndArgs ...any) bool
- func NotEqual(t TestingT, want, give any, fmtAndArgs ...any) bool
- func NotNil(t TestingT, give any, fmtAndArgs ...any) bool
- func NotPanics(t TestingT, fn PanicRunFunc, fmtAndArgs ...any) bool
- func NotSame(t TestingT, want, actual any, fmtAndArgs ...any) bool
- func Panics(t TestingT, fn PanicRunFunc, fmtAndArgs ...any) bool
- func PanicsErrMsg(t TestingT, fn PanicRunFunc, errMsg string, fmtAndArgs ...any) bool
- func PanicsMsg(t TestingT, fn PanicRunFunc, wantVal any, fmtAndArgs ...any) bool
- func Same(t TestingT, wanted, actual any, fmtAndArgs ...any) bool
- func StrContains(t TestingT, s, sub string, fmtAndArgs ...any) bool
- func True(t TestingT, give bool, fmtAndArgs ...any) bool
- type Assertions
- func (as *Assertions) Contains(src, elem any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) ContainsKey(mp, key any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Empty(give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Eq(want, give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Err(err error, fmtAndArgs ...any) *Assertions
- func (as *Assertions) ErrIs(err, wantErr error, fmtAndArgs ...any) *Assertions
- func (as *Assertions) ErrMsg(err error, errMsg string, fmtAndArgs ...any) *Assertions
- func (as *Assertions) ErrSubMsg(err error, subMsg string, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Fail(failMsg string, fmtAndArgs ...any) *Assertions
- func (as *Assertions) FailNow(failMsg string, fmtAndArgs ...any) *Assertions
- func (as *Assertions) False(give bool, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Gt(give, min int, fmtAndArgs ...any) *Assertions
- func (as *Assertions) IsFail() bool
- func (as *Assertions) IsOk() bool
- func (as *Assertions) IsType(wantType, give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Len(give any, wantLn int, fmtAndArgs ...any) *Assertions
- func (as *Assertions) LenGt(give any, minLn int, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Lt(give, max int, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Neq(want, give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Nil(give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) NoErr(err error, fmtAndArgs ...any) *Assertions
- func (as *Assertions) NotContains(src, elem any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) NotEmpty(give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) NotEq(want, give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) NotNil(val any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) NotPanics(fn PanicRunFunc, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Panics(fn PanicRunFunc, fmtAndArgs ...any) *Assertions
- func (as *Assertions) PanicsErrMsg(fn PanicRunFunc, errMsg string, fmtAndArgs ...any) *Assertions
- func (as *Assertions) PanicsMsg(fn PanicRunFunc, wantVal any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) StrContains(s, sub string, fmtAndArgs ...any) *Assertions
- func (as *Assertions) True(give bool, fmtAndArgs ...any) *Assertions
- type PanicRunFunc
- type TestingT
Constants ¶
This section is empty.
Variables ¶
var ( // ShowFullPath on show error trace ShowFullPath = true // EnableColor on show error trace EnableColor = true )
Functions ¶
func Contains ¶
Contains asserts that the given data(string,slice,map) should contain element
TIP: only support types: string, map, array, slice
map - check key exists string - check sub-string exists array,slice - check sub-element exists
func ContainsKey ¶
ContainsKey asserts that the given map is contains key
func ContainsKeys ¶ added in v0.5.8
ContainsKeys asserts that the map is contains all given keys
Usage:
ContainsKeys(t, map[string]any{...}, []string{"key1", "key2"})
func ErrSubMsg ¶
ErrSubMsg asserts that the given is a not nil error and the error message contains subMsg
func IsKind ¶ added in v0.5.9
IsKind assert data reflect.Kind equals. If `give` is ptr or interface, will get real kind.
Usage:
assert.IsKind(t, reflect.Int, val) // assert type is int kind.
func IsType ¶ added in v0.5.8
IsType assert data type equals
Usage:
assert.IsType(t, 0, val) // assert type is int
func NotContains ¶ added in v0.5.7
NotContains asserts that the given data(string,slice,map) should not contain element
TIP: only support types: string, map, array, slice
map - check key exists string - check sub-string exists array,slice - check sub-element exists
func NotEqual ¶ added in v0.6.0
NotEqual asserts that the want should not be equal to the given.
alias of NotEq()
func NotPanics ¶
func NotPanics(t TestingT, fn PanicRunFunc, fmtAndArgs ...any) bool
NotPanics asserts that the code inside the specified func NOT panics.
func NotSame ¶ added in v0.5.8
NotSame asserts that two pointers do not reference the same object.
assert.NotSame(t, ptr1, ptr2)
Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.
func Panics ¶
func Panics(t TestingT, fn PanicRunFunc, fmtAndArgs ...any) bool
Panics asserts that the code inside the specified func panics.
func PanicsErrMsg ¶
func PanicsErrMsg(t TestingT, fn PanicRunFunc, errMsg string, fmtAndArgs ...any) bool
PanicsErrMsg should panic and with error message
func PanicsMsg ¶
func PanicsMsg(t TestingT, fn PanicRunFunc, wantVal any, fmtAndArgs ...any) bool
PanicsMsg should panic and with a value
func Same ¶ added in v0.5.8
Same asserts that two pointers reference the same object.
assert.Same(t, ptr1, ptr2)
Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.
func StrContains ¶
StrContains asserts that the given strings is contains sub-string
Types ¶
type Assertions ¶
type Assertions struct {
// contains filtered or unexported fields
}
Assertions provides assertion methods around the TestingT interface.
func New ¶
func New(t TestingT) *Assertions
New makes a new Assertions object for the specified TestingT.
func (*Assertions) Contains ¶
func (as *Assertions) Contains(src, elem any, fmtAndArgs ...any) *Assertions
Contains asserts that the given data(string,slice,map) should contain element
func (*Assertions) ContainsKey ¶
func (as *Assertions) ContainsKey(mp, key any, fmtAndArgs ...any) *Assertions
ContainsKey asserts that the given map is contains key
func (*Assertions) Empty ¶
func (as *Assertions) Empty(give any, fmtAndArgs ...any) *Assertions
func (*Assertions) Eq ¶
func (as *Assertions) Eq(want, give any, fmtAndArgs ...any) *Assertions
Eq asserts that the want should equal to the given
func (*Assertions) Err ¶
func (as *Assertions) Err(err error, fmtAndArgs ...any) *Assertions
Err asserts that the given is a not nil error
func (*Assertions) ErrIs ¶ added in v0.5.10
func (as *Assertions) ErrIs(err, wantErr error, fmtAndArgs ...any) *Assertions
ErrIs asserts that the given error is equals wantErr
func (*Assertions) ErrMsg ¶
func (as *Assertions) ErrMsg(err error, errMsg string, fmtAndArgs ...any) *Assertions
ErrMsg asserts that the given is a not nil error and error message equals wantMsg
func (*Assertions) ErrSubMsg ¶
func (as *Assertions) ErrSubMsg(err error, subMsg string, fmtAndArgs ...any) *Assertions
ErrSubMsg asserts that the given is a not nil error and the error message contains subMsg
func (*Assertions) Fail ¶
func (as *Assertions) Fail(failMsg string, fmtAndArgs ...any) *Assertions
Fail reports a failure through
func (*Assertions) FailNow ¶
func (as *Assertions) FailNow(failMsg string, fmtAndArgs ...any) *Assertions
FailNow fails test
func (*Assertions) False ¶
func (as *Assertions) False(give bool, fmtAndArgs ...any) *Assertions
func (*Assertions) Gt ¶
func (as *Assertions) Gt(give, min int, fmtAndArgs ...any) *Assertions
Gt asserts that the give(intX) should not be greater than max
func (*Assertions) IsType ¶ added in v0.5.8
func (as *Assertions) IsType(wantType, give any, fmtAndArgs ...any) *Assertions
IsType type equals assert
func (*Assertions) Len ¶
func (as *Assertions) Len(give any, wantLn int, fmtAndArgs ...any) *Assertions
Len assert given length is equals to wantLn
func (*Assertions) LenGt ¶
func (as *Assertions) LenGt(give any, minLn int, fmtAndArgs ...any) *Assertions
LenGt assert given length is greater than to minLn
func (*Assertions) Lt ¶
func (as *Assertions) Lt(give, max int, fmtAndArgs ...any) *Assertions
Lt asserts that the give(intX) should not be less than max
func (*Assertions) Neq ¶
func (as *Assertions) Neq(want, give any, fmtAndArgs ...any) *Assertions
Neq asserts that the want should not be equal to the given. alias of NotEq()
func (*Assertions) Nil ¶
func (as *Assertions) Nil(give any, fmtAndArgs ...any) *Assertions
func (*Assertions) NoErr ¶
func (as *Assertions) NoErr(err error, fmtAndArgs ...any) *Assertions
NoErr asserts that the given is a nil error
func (*Assertions) NotContains ¶ added in v0.5.7
func (as *Assertions) NotContains(src, elem any, fmtAndArgs ...any) *Assertions
NotContains asserts that the given data(string,slice,map) should not contain element
func (*Assertions) NotEmpty ¶
func (as *Assertions) NotEmpty(give any, fmtAndArgs ...any) *Assertions
func (*Assertions) NotEq ¶
func (as *Assertions) NotEq(want, give any, fmtAndArgs ...any) *Assertions
NotEq asserts that the want should not be equal to the given
func (*Assertions) NotNil ¶
func (as *Assertions) NotNil(val any, fmtAndArgs ...any) *Assertions
NotNil asserts that the given is a not nil value
func (*Assertions) NotPanics ¶
func (as *Assertions) NotPanics(fn PanicRunFunc, fmtAndArgs ...any) *Assertions
func (*Assertions) Panics ¶
func (as *Assertions) Panics(fn PanicRunFunc, fmtAndArgs ...any) *Assertions
func (*Assertions) PanicsErrMsg ¶
func (as *Assertions) PanicsErrMsg(fn PanicRunFunc, errMsg string, fmtAndArgs ...any) *Assertions
func (*Assertions) PanicsMsg ¶
func (as *Assertions) PanicsMsg(fn PanicRunFunc, wantVal any, fmtAndArgs ...any) *Assertions
func (*Assertions) StrContains ¶
func (as *Assertions) StrContains(s, sub string, fmtAndArgs ...any) *Assertions
StrContains asserts that the given strings is contains sub-string
func (*Assertions) True ¶
func (as *Assertions) True(give bool, fmtAndArgs ...any) *Assertions