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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
func Condition(t TestingT, comp Comparison, msgAndArgs ...interface{}) bool
Condition uses a Comparison to assert a complex condition.
func Conditionf ¶ added in v1.0.5026
func Conditionf(t TestingT, comp Comparison, msg string, args ...any) bool
Conditionf uses a Comparison to assert a complex condition.
func Contains ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
EqualError asserts that a function returned an error (i.e. not `nil`) and that it is equal to the provided error.
func EqualErrorf ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
EqualValues asserts that two objects are equal or convertible to the larger type and equal.
test.EqualValues(t, uint32(123), int32(123))
func EqualValuesf ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
ErrorContains asserts that a function returned an error (i.e. not `nil`) and that the error contains the specified substring.
func ErrorContainsf ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
ErrorIs asserts that at least one of the errors in err's chain matches target. This is a wrapper for errors.Is.
func ErrorIsf ¶ added in v1.0.5026
ErrorIsf asserts that at least one of the errors in err's chain matches target. This is a wrapper for errors.Is.
func Errorf ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
Exactly asserts that two objects are equal in value and type.
test.Exactly(t, int32(123), int64(123))
func Exactlyf ¶ added in v1.0.5026
Exactlyf asserts that two objects are equal in value and type.
test.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted")
func False ¶ added in v1.0.5026
False asserts that the specified value is false.
test.False(t, myBool)
func Falsef ¶ added in v1.0.5026
Falsef asserts that the specified value is false.
test.Falsef(t, myBool, "error message %s", "formatted")
func Len ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
Nilf asserts that the specified object is nil.
test.Nilf(t, err, "error message %s", "formatted")
func NoErrorf ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
NotEqual asserts that the specified values are NOT equal.
test.NotEqual(t, obj1, obj2)
func NotEqualValues ¶ added in v1.0.5026
NotEqualValues asserts that two objects are not equal even when converted to the same type
test.NotEqualValues(t, obj1, obj2)
func NotEqualValuesf ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
NotErrorAs asserts that none of the errors in err's chain matches target, but if so, sets target to that error value.
func NotErrorAsf ¶ added in v1.0.5026
NotErrorAsf asserts that none of the errors in err's chain matches target, but if so, sets target to that error value.
func NotErrorIs ¶ added in v1.0.5026
NotErrorIs asserts that none of the errors in err's chain matches target. This is a wrapper for errors.Is.
func NotErrorIsf ¶ added in v1.0.5026
NotErrorIsf asserts that none of the errors in err's chain matches target. This is a wrapper for errors.Is.
func NotNil ¶ added in v1.0.5026
NotNil asserts that the specified object is not nil.
NotNil(t, err)
func NotNilf ¶ added in v1.0.5026
NotNilf asserts that the specified object is not nil.
test.NotNilf(t, err, "error message %s", "formatted")
func NotPanics ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 NotSame ¶ added in v1.0.5026
NotSame asserts that two pointers do not reference the same object.
func NotSamef ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
ObjectsAreEqual determines if two objects are considered equal.
func ObjectsAreEqualValues ¶ added in v1.0.5026
ObjectsAreEqualValues gets whether two objects are equal, or if their values are equal.
func ObjectsExportedFieldsAreEqual ¶ added in v1.0.5026
func Panics ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
Truef asserts that the specified value is true.
test.Truef(t, myBool, "error message %s", "formatted")
func WithinDuration ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
BoolAssertionFunc is a common function prototype when validating a bool value. Can be useful for table driven tests.
type Comparison ¶ added in v1.0.5026
type Comparison func() (success bool)
Comparison is a custom function that returns true on success and false on failure
type ComparisonAssertionFunc ¶ added in v1.0.5026
ComparisonAssertionFunc is a common function prototype when comparing two values. Can be useful for table driven tests.
type ErrorAssertionFunc ¶ added in v1.0.5026
ErrorAssertionFunc is a common function prototype when validating an error value. Can be useful for table driven tests.
type PanicAssertionFunc ¶ added in v1.0.5026
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 ¶ added in v1.0.5026
type PanicTestFunc func()