Documentation
¶
Index ¶
- func EqualComplexes(t testing.TB, want, got complex128, details ...interface{})
- func EqualErrs(t testing.TB, want, got error, details ...interface{})
- func EqualFloats(t testing.TB, want, got float64, details ...interface{})
- func EqualInts(t testing.TB, want int, got int, details ...interface{})
- func EqualStrings(t testing.TB, want string, got string, details ...interface{})
- func Err(assert *Assert, message string)
- func Error(t testing.TB, err error, details ...interface{})
- func Fatal(assert *Assert, message string)
- func IsError(t testing.TB, got, want error, details ...interface{})
- func IsTrue(t testing.TB, cond bool, details ...interface{})
- func NoError(t testing.TB, err error, details ...interface{})
- func Partial(t testing.TB, obj interface{}, target interface{}, details ...interface{})
- func StringContains(t testing.TB, s, substr string, details ...interface{})
- func StringMatch(t testing.TB, pattern string, str string, details ...interface{})
- type Assert
- func (assert *Assert) EqualBools(want bool, got bool, details ...interface{})
- func (assert *Assert) EqualComplexes(want, got complex128, details ...interface{})
- func (assert *Assert) EqualErrs(want error, got error, details ...interface{})
- func (assert *Assert) EqualFloats(want float64, got float64, details ...interface{})
- func (assert *Assert) EqualInts(want int, got int, details ...interface{})
- func (assert *Assert) EqualStrings(want string, got string, details ...interface{})
- func (assert *Assert) EqualUints(want uint64, got uint64, details ...interface{})
- func (assert *Assert) Error(err error, details ...interface{})
- func (assert *Assert) IsError(got, want error, details ...interface{})
- func (assert *Assert) IsFalse(b bool, details ...interface{})
- func (assert *Assert) IsTrue(b bool, details ...interface{})
- func (assert *Assert) NoError(err error, details ...interface{})
- func (assert *Assert) Partial(obj, target interface{}, details ...interface{})
- func (assert *Assert) StringContains(s string, substr string, details ...interface{})
- func (assert *Assert) StringMatch(pattern string, str string, details ...interface{})
- type FailureReport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EqualComplexes ¶
func EqualComplexes(t testing.TB, want, got complex128, details ...interface{})
EqualComplexes compares the two complex numbers for equality. If they are not equal then the Fatal function is called with details.
func EqualErrs ¶
EqualErrs compares if two errors have the same error description (by calling .Error()). If they are not equal then the Fatal() function is called with details. Both errors can't be nil.
func EqualFloats ¶
EqualFloats compares the two floats for equality. If they are not equal then the Fatal() function is called with details.
func EqualInts ¶
EqualInts compares the two ints for equality. If they are not equal then the Fatal() function is called with details.
func EqualStrings ¶
EqualStrings compares the two strings for equality. If they are not equal then the Fatal() function is called with details.
func IsError ¶
IsError will assert if the given error matches the want error. It uses the errors.Is() function to check if the error wraps the wanted error. It calls the Fatal() function if errors.Is() returns false.
func NoError ¶
NoError will assert that given error is nil. If it's nil then the Fatal() function is called with details.
func StringContains ¶
StringContains asserts that string s contains the subst string and calls the Fatal() function with details otherwise.
Types ¶
type Assert ¶
type Assert struct {
// contains filtered or unexported fields
}
Assert is a custom assert helper.
func New ¶
func New(t testing.TB, fail FailureReport, details ...interface{}) *Assert
New creates a new assert helper object with a custom fail function and an optional context detail. For calling t.Fatal() or t.Error() in case of failures, see Fatal() and Err() respectively. Example:
assert := assert.New(t, assert.Fatal)
The variadic details parameter must be a string format followed by its format arguments. Example:
v1.Name = "test" v2.Name = "tesd" assert := assert.New(t, assert.Err, "comparing objects %s and %s", v1, v2) assert.EqualStrings(v1.Name, v2.Name, "Name mismatch") ...
The code above fails with message below:
wanted[test] but got[tesd].Name mismatch: comparing objects Value1 and Value2
func (*Assert) EqualBools ¶
EqualBools asserts two booleans for equality. If they are not the equal then the failure function is called.
func (*Assert) EqualComplexes ¶
func (assert *Assert) EqualComplexes(want, got complex128, details ...interface{})
EqualComplexes compares the two complex numbers for equality. If they are not equal then the failure function is called with details.
func (*Assert) EqualErrs ¶
EqualErrs compares if two errors have the same error description (by calling .Error()). If they are not equal then the failure function is called with details. Both errors can't be nil.
func (*Assert) EqualFloats ¶
EqualFloats compares the two floats for equality. If they are not equal then the failure function is called with details.
func (*Assert) EqualInts ¶
EqualInts compares the two ints for equality. If they are not equal then the failure function is called with details.
func (*Assert) EqualStrings ¶
EqualStrings compares the two strings for equality. If they are not equal then the failure function is called with details.
func (*Assert) EqualUints ¶
EqualUints compares the two uint64s for equality. If they are not equal then the failure function is called with details.
func (*Assert) Error ¶
Error will call the failure function with the given details if the error is nil.
func (*Assert) IsError ¶
IsError will assert if the given error matches the want error. It uses the errors.Is() function to check if the error wraps the wanted error. It calls the failure function if errors.Is() returns false.
func (*Assert) IsFalse ¶
IsFalse asserts that b is false. If it's not then the failure function is called with details.
func (*Assert) IsTrue ¶
IsTrue asserts that b is true. If it's not then the failure function is called with details.
func (*Assert) NoError ¶
NoError will assert that given error is nil. If it's nil then the failure function is called with details.
func (*Assert) Partial ¶
func (assert *Assert) Partial(obj, target interface{}, details ...interface{})
Partial recursively asserts that obj partially matches target. Below are the assertion rules: - booleans, integers, floats and complex numbers must be equal. - strings, slices, array and map: the obj must contains the target. - structs: the obj fields must recursively 8match the target fields.
func (*Assert) StringContains ¶
StringContains asserts that string s contains the subst string and calls the failure function with details otherwise.
func (*Assert) StringMatch ¶
StringMatch asserts that string matches the regex pattern and calls the failure function with details otherwise.
type FailureReport ¶
FailureReport is the function type used to report assert errors. See assert.Fatal and assert.Err for implementations.