Documentation
¶
Index ¶
- func AssertEmptyT(t *testing.T) func(any, string)
- func AssertEqualT(t *testing.T) func(any, any, string)
- func AssertErrorT(t *testing.T) func(error, string)
- func AssertFalseT(t *testing.T) func(bool, string)
- func AssertNoErrorT(t *testing.T) func(error, string)
- func AssertNotEmptyT(t *testing.T) func(any, string)
- func AssertNotEqualT(t *testing.T) func(any, any, string)
- func AssertTrueT(t *testing.T) func(bool, string)
- func CallerInfo() []string
- func Condition(t TestingT, comp Comparison, msgAndArgs ...interface{}) bool
- func Conditionf(t TestingT, comp Comparison, msg string, args ...any) bool
- func Contains(t TestingT, s, contains any, msgAndArgs ...any) bool
- func Containsf(t TestingT, s any, contains any, msg string, args ...any) bool
- func Empty(t TestingT, object any, msgAndArgs ...any) bool
- func Emptyf(t TestingT, object any, msg string, args ...any) bool
- func Equal(t TestingT, expected, actual any, msgAndArgs ...any) bool
- func EqualError(t TestingT, theError error, errString string, msgAndArgs ...any) bool
- func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...any) bool
- func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func EqualExportedValuesf(t TestingT, expected any, actual any, msg string, args ...any) bool
- func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func EqualValuesf(t TestingT, expected any, actual any, msg string, args ...any) bool
- func Equalf(t TestingT, expected any, actual any, msg string, args ...any) bool
- func Error(t TestingT, err error, msgAndArgs ...any) bool
- func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) bool
- func ErrorAsf(t TestingT, err error, target any, msg string, args ...any) bool
- func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...any) bool
- func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...any) bool
- func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool
- func ErrorIsf(t TestingT, err error, target error, msg string, args ...any) bool
- func Errorf(t TestingT, err error, msg string, args ...any) bool
- func Exactly(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func Exactlyf(t TestingT, expected any, actual any, msg string, args ...any) bool
- func Fail(t TestingT, failureMessage string, msgAndArgs ...any) bool
- func FailNow(t TestingT, failureMessage string, msgAndArgs ...any) bool
- func FailNowf(t TestingT, failureMessage string, msg string, args ...any) bool
- func Failf(t TestingT, failureMessage string, msg string, args ...any) bool
- func False(t TestingT, value bool, msgAndArgs ...any) bool
- func Falsef(t TestingT, value bool, msg string, args ...any) bool
- func IsType(t TestingT, expectedType any, object any, msgAndArgs ...any) bool
- func IsTypef(t TestingT, expectedType any, object any, msg string, args ...any) bool
- func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) bool
- func MustPanic(t *testing.T, msg string, f func())
- func Nil(t TestingT, object any, msgAndArgs ...any) bool
- func Nilf(t TestingT, object any, msg string, args ...any) bool
- func NoError(t TestingT, err error, msgAndArgs ...any) bool
- func NoErrorf(t TestingT, err error, msg string, args ...any) bool
- func NotContains(t TestingT, s, contains any, msgAndArgs ...any) bool
- func NotContainsf(t TestingT, s any, contains any, msg string, args ...any) bool
- func NotEmpty(t TestingT, object any, msgAndArgs ...any) bool
- func NotEmptyf(t TestingT, object any, msg string, args ...any) bool
- func NotEqual(t TestingT, expected, actual any, msgAndArgs ...any) bool
- func NotEqualValues(t TestingT, expected, actual any, msgAndArgs ...interface{}) bool
- func NotEqualValuesf(t TestingT, expected any, actual any, msg string, args ...any) bool
- func NotEqualf(t TestingT, expected any, actual any, msg string, args ...any) bool
- func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) bool
- func NotErrorAsf(t TestingT, err error, target any, msg string, args ...any) bool
- func NotErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool
- func NotErrorIsf(t TestingT, err error, target error, msg string, args ...any) bool
- func NotNil(t TestingT, object any, msgAndArgs ...any) bool
- func NotNilf(t TestingT, object any, msg string, args ...any) bool
- func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...any) bool
- func NotPanicsf(t TestingT, f PanicTestFunc, msg string, args ...any) bool
- func NotSame(t TestingT, expected, actual any, msgAndArgs ...any) bool
- func NotSamef(t TestingT, expected any, actual any, msg string, args ...any) bool
- func NotSubset(t TestingT, list, subset any, msgAndArgs ...any) (ok bool)
- func NotSubsetf(t TestingT, list any, subset any, msg string, args ...any) bool
- func NotZero(t TestingT, i any, msgAndArgs ...any) bool
- func NotZerof(t TestingT, i any, msg string, args ...any) bool
- func ObjectsAreEqual(expected, actual any) bool
- func ObjectsAreEqualValues(expected, actual any) bool
- func ObjectsExportedFieldsAreEqual(expected, actual any) bool
- func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...any) bool
- func PanicsWithError(t TestingT, errString string, f PanicTestFunc, msgAndArgs ...any) bool
- func PanicsWithErrorf(t TestingT, errString string, f PanicTestFunc, msg string, args ...any) bool
- func PanicsWithValue(t TestingT, expected any, f PanicTestFunc, msgAndArgs ...any) bool
- func PanicsWithValuef(t TestingT, expected any, f PanicTestFunc, msg string, args ...any) bool
- func Panicsf(t TestingT, f PanicTestFunc, msg string, args ...any) bool
- func Same(t TestingT, expected, actual any, msgAndArgs ...any) bool
- func Samef(t TestingT, expected any, actual any, msg string, args ...any) bool
- func Subset(t TestingT, list, subset any, msgAndArgs ...any) (ok bool)
- func Subsetf(t TestingT, list any, subset any, msg string, args ...any) bool
- func True(t TestingT, value bool, msgAndArgs ...any) bool
- func Truef(t TestingT, value bool, msg string, args ...any) bool
- func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration, ...) bool
- func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, ...) bool
- func WithinRange(t TestingT, actual, start, end time.Time, msgAndArgs ...interface{}) bool
- func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, msg string, ...) bool
- func Zero(t TestingT, i any, msgAndArgs ...any) bool
- func Zerof(t TestingT, i any, msg string, args ...any) bool
- type BoolAssertionFunc
- type Comparison
- type ComparisonAssertionFunc
- type ErrorAssertionFunc
- type PanicAssertionFunc
- type PanicTestFunc
- type TestingT
- type ValueAssertionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallerInfo ¶
func CallerInfo() []string
CallerInfo returns an array of strings containing the file and line number of each stack frame leading from the current test to the assert call that failed.
func Condition ¶
func Condition(t TestingT, comp Comparison, msgAndArgs ...interface{}) bool
Condition uses a Comparison to assert a complex condition.
func Conditionf ¶
func Conditionf(t TestingT, comp Comparison, msg string, args ...any) bool
Conditionf uses a Comparison to assert a complex condition.
func Contains ¶
Contains asserts that the specified string, list(array, slice...) or map contains the specified substring or element.
test.Contains(t, "Hello World", "World")
test.Contains(t, ["Hello", "World"], "World")
test.Contains(t, {"Hello": "World"}, "Hello")
func Containsf ¶
Containsf asserts that the specified string, list(array, slice...) or map contains the specified substring or element.
test.Containsf(t, "Hello World", "World", "error message %s", "formatted")
test.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted")
test.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted")
func Empty ¶
Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either a slice or a channel with len == 0.
test.Empty(t, obj)
func Emptyf ¶
Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either a slice or a channel with len == 0.
test.Emptyf(t, obj, "error message %s", "formatted")
func EqualError ¶
EqualError asserts that a function returned an error (i.e. not `nil`) and that it is equal to the provided error.
func EqualErrorf ¶
EqualErrorf asserts that a function returned an error (i.e. not `nil`) and that it is equal to the provided error.
actualObj, err := SomeFunction() test.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted")
func EqualExportedValues ¶
EqualExportedValues asserts that the types of two objects are equal and their public fields are also equal. This is useful for comparing structs that have private fields that could potentially differ.
type S struct {
Exported int
notExported int
}
test.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true
test.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false
func EqualExportedValuesf ¶
EqualExportedValuesf asserts that the types of two objects are equal and their public fields are also equal. This is useful for comparing structs that have private fields that could potentially differ.
type S struct {
Exported int
notExported int
}
test.EqualExportedValuesf(t, S{1, 2}, S{1, 3}, "error message %s", "formatted") => true
test.EqualExportedValuesf(t, S{1, 2}, S{2, 3}, "error message %s", "formatted") => false
func EqualValues ¶
EqualValues asserts that two objects are equal or convertible to the larger type and equal.
test.EqualValues(t, uint32(123), int32(123))
func EqualValuesf ¶
EqualValuesf asserts that two objects are equal or convertible to the larger type and equal.
test.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted")
func Equalf ¶
Equalf asserts that two objects are equal.
test.Equalf(t, 123, 123, "error message %s", "formatted")
Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses). Function equality cannot be determined and will always fail.
func ErrorAs ¶
ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. This is a wrapper for errors.As.
func ErrorAsf ¶
ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. This is a wrapper for errors.As.
func ErrorContains ¶
ErrorContains asserts that a function returned an error (i.e. not `nil`) and that the error contains the specified substring.
func ErrorContainsf ¶
ErrorContainsf asserts that a function returned an error (i.e. not `nil`) and that the error contains the specified substring.
actualObj, err := SomeFunction() test.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted")
func ErrorIs ¶
ErrorIs asserts that at least one of the errors in err's chain matches target. This is a wrapper for errors.Is.
func ErrorIsf ¶
ErrorIsf asserts that at least one of the errors in err's chain matches target. This is a wrapper for errors.Is.
func Errorf ¶
Errorf asserts that a function returned an error (i.e. not `nil`).
actualObj, err := SomeFunction()
if test.Errorf(t, err, "error message %s", "formatted") {
test.Equal(t, expectedErrorf, err)
}
func Exactly ¶
Exactly asserts that two objects are equal in value and type.
test.Exactly(t, int32(123), int64(123))
func Exactlyf ¶
Exactlyf asserts that two objects are equal in value and type.
test.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted")
func Falsef ¶
Falsef asserts that the specified value is false.
test.Falsef(t, myBool, "error message %s", "formatted")
func Len ¶
Len asserts that the specified object has specific length. Len also fails if the object has a type that len() not accept.
test.Len(t, mySlice, 3)
func Nilf ¶
Nilf asserts that the specified object is nil.
test.Nilf(t, err, "error message %s", "formatted")
func NoErrorf ¶
NoErrorf asserts that a function returned no error (i.e. `nil`).
actualObj, err := SomeFunction()
if test.NoErrorf(t, err, "error message %s", "formatted") {
test.Equal(t, expectedObj, actualObj)
}
func NotContains ¶
NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.
test.NotContains(t, "Hello World", "Earth")
test.NotContains(t, ["Hello", "World"], "Earth")
test.NotContains(t, {"Hello": "World"}, "Earth")
func NotContainsf ¶
NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.
test.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted")
test.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted")
test.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted")
func NotEmpty ¶
NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either a slice or a channel with len == 0.
if test.NotEmpty(t, obj) {
test.Equal(t, "two", obj[1])
}
func NotEmptyf ¶
NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either a slice or a channel with len == 0.
if test.NotEmptyf(t, obj, "error message %s", "formatted") {
test.Equal(t, "two", obj[1])
}
func NotEqual ¶
NotEqual asserts that the specified values are NOT equal.
test.NotEqual(t, obj1, obj2)
func NotEqualValues ¶
NotEqualValues asserts that two objects are not equal even when converted to the same type
test.NotEqualValues(t, obj1, obj2)
func NotEqualValuesf ¶
NotEqualValuesf asserts that two objects are not equal even when converted to the same type
test.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted")
func NotEqualf ¶
NotEqualf asserts that the specified values are NOT equal.
test.NotEqualf(t, obj1, obj2, "error message %s", "formatted")
Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses).
func NotErrorAs ¶
NotErrorAs asserts that none of the errors in err's chain matches target, but if so, sets target to that error value.
func NotErrorAsf ¶
NotErrorAsf asserts that none of the errors in err's chain matches target, but if so, sets target to that error value.
func NotErrorIs ¶
NotErrorIs asserts that none of the errors in err's chain matches target. This is a wrapper for errors.Is.
func NotErrorIsf ¶
NotErrorIsf asserts that none of the errors in err's chain matches target. This is a wrapper for errors.Is.
func NotNilf ¶
NotNilf asserts that the specified object is not nil.
test.NotNilf(t, err, "error message %s", "formatted")
func NotPanics ¶
func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...any) bool
NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
test.NotPanics(t, func(){ RemainCalm() })
func NotPanicsf ¶
func NotPanicsf(t TestingT, f PanicTestFunc, msg string, args ...any) bool
NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
test.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted")
func NotSamef ¶
NotSamef asserts that two pointers do not reference the same object.
test.NotSamef(t, ptr1, ptr2, "error message %s", "formatted")
Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.
func NotSubset ¶
NotSubset asserts that the specified list(array, slice...) or map does NOT contain all elements given in the specified subset list(array, slice...) or map.
test.NotSubset(t, [1, 3, 4], [1, 2])
test.NotSubset(t, {"x": 1, "y": 2}, {"z": 3})
func NotSubsetf ¶
NotSubsetf asserts that the specified list(array, slice...) or map does NOT contain all elements given in the specified subset list(array, slice...) or map.
test.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted")
test.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
func ObjectsAreEqual ¶
ObjectsAreEqual determines if two objects are considered equal.
func ObjectsAreEqualValues ¶
ObjectsAreEqualValues gets whether two objects are equal, or if their values are equal.
func Panics ¶
func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...any) bool
Panics asserts that the code inside the specified PanicTestFunc panics.
test.Panics(t, func(){ GoCrazy() })
func PanicsWithError ¶
func PanicsWithError(t TestingT, errString string, f PanicTestFunc, msgAndArgs ...any) bool
PanicsWithError asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value is an error that satisfies the EqualError comparison.
test.PanicsWithError(t, "crazy error", func(){ GoCrazy() })
func PanicsWithErrorf ¶
PanicsWithErrorf asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value is an error that satisfies the EqualError comparison.
test.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
func PanicsWithValue ¶
func PanicsWithValue(t TestingT, expected any, f PanicTestFunc, msgAndArgs ...any) bool
PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value equals the expected panic value.
test.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })
func PanicsWithValuef ¶
PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value equals the expected panic value.
test.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
func Panicsf ¶
func Panicsf(t TestingT, f PanicTestFunc, msg string, args ...any) bool
Panicsf asserts that the code inside the specified PanicTestFunc panics.
test.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted")
func Samef ¶
Samef asserts that two pointers reference the same object.
test.Samef(t, ptr1, ptr2, "error message %s", "formatted")
Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.
func Subset ¶
Subset asserts that the specified list(array, slice...) or map contains all elements given in the specified subset list(array, slice...) or map.
test.Subset(t, [1, 2, 3], [1, 2])
test.Subset(t, {"x": 1, "y": 2}, {"x": 1})
func Subsetf ¶
Subsetf asserts that the specified list(array, slice...) or map contains all elements given in the specified subset list(array, slice...) or map.
test.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted")
test.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
func Truef ¶
Truef asserts that the specified value is true.
test.Truef(t, myBool, "error message %s", "formatted")
func WithinDuration ¶
func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool
WithinDuration asserts that the two times are within duration delta of each other.
test.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
func WithinDurationf ¶
func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...any) bool
WithinDurationf asserts that the two times are within duration delta of each other.
test.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
func WithinRange ¶
WithinRange asserts that a time is within a time range (inclusive).
test.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second))
func WithinRangef ¶
func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, msg string, args ...any) bool
WithinRangef asserts that a time is within a time range (inclusive).
test.WithinRangef(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second), "error message %s", "formatted")
Types ¶
type BoolAssertionFunc ¶
BoolAssertionFunc is a common function prototype when validating a bool value. Can be useful for table driven tests.
type Comparison ¶
type Comparison func() (success bool)
Comparison is a custom function that returns true on success and false on failure
type ComparisonAssertionFunc ¶
ComparisonAssertionFunc is a common function prototype when comparing two values. Can be useful for table driven tests.
type ErrorAssertionFunc ¶
ErrorAssertionFunc is a common function prototype when validating an error value. Can be useful for table driven tests.
type PanicAssertionFunc ¶
type PanicAssertionFunc = func(t TestingT, f PanicTestFunc, msgAndArgs ...any) bool
PanicAssertionFunc is a common function prototype when validating a panic value. Can be useful for table driven tests.
type PanicTestFunc ¶
type PanicTestFunc func()