Documentation ¶
Overview ¶
Package assert provides a set of comprehensive debug assertions.
Example Usage ¶
The following is a complete example using assert in a function:
import ( "github.com/negrel/assert" ) func Divide(a, b int) int { assert.NotEqual(b, 0, "Can't divide by 0.") return a / b }
Debug Assertions ¶
Debug assertions are programming statements that help developers catch logical errors during development by verifying assumptions about the program's state. They're typically used to check conditions that should always be true during normal program execution. If the condition is false, the assertions is either wrong or there is a programming error. In both case, program panics if it was compiled with the `assert` tags (`go build -tags assert ./path/to/my/package`)
Every assertion function also takes an optional string message as the final argument, allowing custom error messages to be appended to the message the assertion method outputs.
Index ¶
- Variables
- func CallerInfo()
- func Condition(comp Comparison, msgAndArgs ...interface{})
- func Conditionf(comp Comparison, msg string, args ...interface{})
- func Contains(s, contains interface{}, msgAndArgs ...interface{})
- func Containsf(s interface{}, contains interface{}, msg string, args ...interface{})
- func DirExists(path string, msgAndArgs ...interface{})
- func DirExistsf(path string, msg string, args ...interface{})
- func ElementsMatch(listA, listB interface{}, msgAndArgs ...interface{})
- func ElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{})
- func Empty(object interface{}, msgAndArgs ...interface{})
- func Emptyf(object interface{}, msg string, args ...interface{})
- func Equal(expected, actual interface{}, msgAndArgs ...interface{})
- func EqualError(theError error, errString string, msgAndArgs ...interface{})
- func EqualErrorf(theError error, errString string, msg string, args ...interface{})
- func EqualExportedValues(expected, actual interface{}, msgAndArgs ...interface{})
- func EqualExportedValuesf(expected interface{}, actual interface{}, msg string, args ...interface{})
- func EqualValues(expected, actual interface{}, msgAndArgs ...interface{})
- func EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{})
- func Equalf(expected interface{}, actual interface{}, msg string, args ...interface{})
- func Error(err error, msgAndArgs ...interface{})
- func ErrorAs(err error, target interface{}, msgAndArgs ...interface{})
- func ErrorAsf(err error, target interface{}, msg string, args ...interface{})
- func ErrorContains(theError error, contains string, msgAndArgs ...interface{})
- func ErrorContainsf(theError error, contains string, msg string, args ...interface{})
- func ErrorIs(err, target error, msgAndArgs ...interface{})
- func ErrorIsf(err error, target error, msg string, args ...interface{})
- func Errorf(err error, msg string, args ...interface{})
- func Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, ...)
- func Eventuallyf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, ...)
- func Exactly(expected, actual interface{}, msgAndArgs ...interface{})
- func Exactlyf(expected interface{}, actual interface{}, msg string, args ...interface{})
- func Fail(failureMessage string, msgAndArgs ...interface{})
- func FailNow(failureMessage string, msgAndArgs ...interface{})
- func FailNowf(failureMessage string, msg string, args ...interface{})
- func Failf(failureMessage string, msg string, args ...interface{})
- func False(value bool, msgAndArgs ...interface{})
- func Falsef(value bool, msg string, args ...interface{})
- func FileExists(path string, msgAndArgs ...interface{})
- func FileExistsf(path string, msg string, args ...interface{})
- func Greater(e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
- func GreaterOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
- func GreaterOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{})
- func Greaterf(e1 interface{}, e2 interface{}, msg string, args ...interface{})
- func HTTPBody(handler http.HandlerFunc, method, url string, values url.Values)
- func HTTPBodyContains(handler http.HandlerFunc, method, url string, values url.Values, ...)
- func HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, ...)
- func HTTPBodyNotContains(handler http.HandlerFunc, method, url string, values url.Values, ...)
- func HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, ...)
- func HTTPError(handler http.HandlerFunc, method, url string, values url.Values, ...)
- func HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, ...)
- func HTTPRedirect(handler http.HandlerFunc, method, url string, values url.Values, ...)
- func HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, ...)
- func HTTPStatusCode(handler http.HandlerFunc, method, url string, values url.Values, ...)
- func HTTPStatusCodef(handler http.HandlerFunc, method string, url string, values url.Values, ...)
- func HTTPSuccess(handler http.HandlerFunc, method, url string, values url.Values, ...)
- func HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, ...)
- func Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{})
- func Implementsf(interfaceObject interface{}, object interface{}, msg string, ...)
- func InDelta(expected, actual interface{}, delta float64, msgAndArgs ...interface{})
- func InDeltaMapValues(expected, actual interface{}, delta float64, msgAndArgs ...interface{})
- func InDeltaMapValuesf(expected interface{}, actual interface{}, delta float64, msg string, ...)
- func InDeltaSlice(expected, actual interface{}, delta float64, msgAndArgs ...interface{})
- func InDeltaSlicef(expected interface{}, actual interface{}, delta float64, msg string, ...)
- func InDeltaf(expected interface{}, actual interface{}, delta float64, msg string, ...)
- func InEpsilon(expected, actual interface{}, epsilon float64, msgAndArgs ...interface{})
- func InEpsilonSlice(expected, actual interface{}, epsilon float64, msgAndArgs ...interface{})
- func InEpsilonSlicef(expected interface{}, actual interface{}, epsilon float64, msg string, ...)
- func InEpsilonf(expected interface{}, actual interface{}, epsilon float64, msg string, ...)
- func IsDecreasing(object interface{}, msgAndArgs ...interface{})
- func IsDecreasingf(object interface{}, msg string, args ...interface{})
- func IsIncreasing(object interface{}, msgAndArgs ...interface{})
- func IsIncreasingf(object interface{}, msg string, args ...interface{})
- func IsNonDecreasing(object interface{}, msgAndArgs ...interface{})
- func IsNonDecreasingf(object interface{}, msg string, args ...interface{})
- func IsNonIncreasing(object interface{}, msgAndArgs ...interface{})
- func IsNonIncreasingf(object interface{}, msg string, args ...interface{})
- func IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{})
- func IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{})
- func JSONEq(expected string, actual string, msgAndArgs ...interface{})
- func JSONEqf(expected string, actual string, msg string, args ...interface{})
- func Len(object interface{}, length int, msgAndArgs ...interface{})
- func Lenf(object interface{}, length int, msg string, args ...interface{})
- func Less(e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
- func LessOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
- func LessOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{})
- func Lessf(e1 interface{}, e2 interface{}, msg string, args ...interface{})
- func Locked(locker TryLocker, msgAndArgs ...any)
- func Lockedf(locker TryLocker, msg string, args ...any)
- func Negative(e interface{}, msgAndArgs ...interface{})
- func Negativef(e interface{}, msg string, args ...interface{})
- func Never(condition func() bool, waitFor time.Duration, tick time.Duration, ...)
- func Neverf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, ...)
- func Nil(object interface{}, msgAndArgs ...interface{})
- func Nilf(object interface{}, msg string, args ...interface{})
- func NoDirExists(path string, msgAndArgs ...interface{})
- func NoDirExistsf(path string, msg string, args ...interface{})
- func NoError(err error, msgAndArgs ...interface{})
- func NoErrorf(err error, msg string, args ...interface{})
- func NoFileExists(path string, msgAndArgs ...interface{})
- func NoFileExistsf(path string, msg string, args ...interface{})
- func NotContains(s, contains interface{}, msgAndArgs ...interface{})
- func NotContainsf(s interface{}, contains interface{}, msg string, args ...interface{})
- func NotElementsMatch(listA, listB interface{}, msgAndArgs ...interface{})
- func NotElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{})
- func NotEmpty(object interface{}, msgAndArgs ...interface{})
- func NotEmptyf(object interface{}, msg string, args ...interface{})
- func NotEqual(expected, actual interface{}, msgAndArgs ...interface{})
- func NotEqualValues(expected, actual interface{}, msgAndArgs ...interface{})
- func NotEqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{})
- func NotEqualf(expected interface{}, actual interface{}, msg string, args ...interface{})
- func NotErrorAs(err error, target interface{}, msgAndArgs ...interface{})
- func NotErrorAsf(err error, target interface{}, msg string, args ...interface{})
- func NotErrorIs(err, target error, msgAndArgs ...interface{})
- func NotErrorIsf(err error, target error, msg string, args ...interface{})
- func NotImplements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{})
- func NotImplementsf(interfaceObject interface{}, object interface{}, msg string, ...)
- func NotNil(object interface{}, msgAndArgs ...interface{})
- func NotNilf(object interface{}, msg string, args ...interface{})
- func NotPanics(f PanicTestFunc, msgAndArgs ...interface{})
- func NotPanicsf(f PanicTestFunc, msg string, args ...interface{})
- func NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{})
- func NotRegexpf(rx interface{}, str interface{}, msg string, args ...interface{})
- func NotSame(expected, actual interface{}, msgAndArgs ...interface{})
- func NotSamef(expected interface{}, actual interface{}, msg string, args ...interface{})
- func NotSubset(list, subset interface{}, msgAndArgs ...interface{})
- func NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{})
- func NotZero(i interface{}, msgAndArgs ...interface{})
- func NotZerof(i interface{}, msg string, args ...interface{})
- func ObjectsAreEqual(expected, actual interface{})
- func ObjectsAreEqualValues(expected, actual interface{})
- func ObjectsExportedFieldsAreEqual(expected, actual interface{})deprecated
- func Panics(f PanicTestFunc, msgAndArgs ...interface{})
- func PanicsWithError(errString string, f PanicTestFunc, msgAndArgs ...interface{})
- func PanicsWithErrorf(errString string, f PanicTestFunc, msg string, args ...interface{})
- func PanicsWithValue(expected interface{}, f PanicTestFunc, msgAndArgs ...interface{})
- func PanicsWithValuef(expected interface{}, f PanicTestFunc, msg string, args ...interface{})
- func Panicsf(f PanicTestFunc, msg string, args ...interface{})
- func Positive(e interface{}, msgAndArgs ...interface{})
- func Positivef(e interface{}, msg string, args ...interface{})
- func Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{})
- func Regexpf(rx interface{}, str interface{}, msg string, args ...interface{})
- func Same(expected, actual interface{}, msgAndArgs ...interface{})
- func Samef(expected interface{}, actual interface{}, msg string, args ...interface{})
- func Subset(list, subset interface{}, msgAndArgs ...interface{})
- func Subsetf(list interface{}, subset interface{}, msg string, args ...interface{})
- func True(value bool, msgAndArgs ...interface{})
- func Truef(value bool, msg string, args ...interface{})
- func Unlocked(locker TryLocker, msgAndArgs ...any)
- func Unlockedf(locker TryLocker, msg string, args ...any)
- func WithinDuration(expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{})
- func WithinDurationf(expected time.Time, actual time.Time, delta time.Duration, msg string, ...)
- func WithinRange(actual, start, end time.Time, msgAndArgs ...interface{})
- func WithinRangef(actual time.Time, start time.Time, end time.Time, msg string, ...)
- func Zero(i interface{}, msgAndArgs ...interface{})
- func Zerof(i interface{}, msg string, args ...interface{})
- type BoolAssertionFunc
- type CollectT
- type CompareTypedeprecated
- type Comparison
- type ComparisonAssertionFunc
- type ErrorAssertionFunc
- type PanicAssertionFunc
- type PanicTestFunc
- type TestingT
- type TryLocker
- type ValueAssertionFunc
Constants ¶
This section is empty.
Variables ¶
var AnError = errors.New("assert.AnError general error for testing")
AnError is an error instance useful for testing. If the code does not care about error specifics, and only needs to return the error for example, this error should be used to make the test code more readable.
Functions ¶
func CallerInfo ¶
func CallerInfo()
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(comp Comparison, msgAndArgs ...interface{})
Condition uses a Comparison to assert a complex condition.
func Conditionf ¶
func Conditionf(comp Comparison, msg string, args ...interface{})
Conditionf uses a Comparison to assert a complex condition.
func Contains ¶
func Contains(s, contains interface{}, msgAndArgs ...interface{})
Contains asserts that the specified string, list(array, slice...) or map contains the specified substring or element.
assert.Contains("Hello World", "World") assert.Contains(["Hello", "World"], "World") assert.Contains({"Hello": "World"}, "Hello")
func Containsf ¶
func Containsf(s interface{}, contains interface{}, msg string, args ...interface{})
Containsf asserts that the specified string, list(array, slice...) or map contains the specified substring or element.
assert.Containsf("Hello World", "World", "error message %s", "formatted") assert.Containsf(["Hello", "World"], "World", "error message %s", "formatted") assert.Containsf({"Hello": "World"}, "Hello", "error message %s", "formatted")
func DirExists ¶
func DirExists(path string, msgAndArgs ...interface{})
DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
func DirExistsf ¶
DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
func ElementsMatch ¶
func ElementsMatch(listA, listB interface{}, msgAndArgs ...interface{})
ElementsMatch asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.
assert.ElementsMatch([1, 3, 2, 3], [1, 3, 3, 2])
func ElementsMatchf ¶
func ElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{})
ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.
assert.ElementsMatchf([1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")
func Empty ¶
func Empty(object interface{}, msgAndArgs ...interface{})
Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either a slice or a channel with len == 0.
assert.Empty(obj)
func Emptyf ¶
func Emptyf(object interface{}, msg string, args ...interface{})
Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either a slice or a channel with len == 0.
assert.Emptyf(obj, "error message %s", "formatted")
func Equal ¶
func Equal(expected, actual interface{}, msgAndArgs ...interface{})
Equal asserts that two objects are equal.
assert.Equal(123, 123)
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 EqualError ¶
EqualError asserts that a function returned an error (i.e. not `nil`) and that it is equal to the provided error.
actualObj, err := SomeFunction() assert.EqualError(err, expectedErrorString)
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() assert.EqualErrorf(err, expectedErrorString, "error message %s", "formatted")
func EqualExportedValues ¶
func EqualExportedValues(expected, actual interface{}, msgAndArgs ...interface{})
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 } assert.EqualExportedValues(S{1, 2}, S{1, 3}) => true assert.EqualExportedValues(S{1, 2}, S{2, 3}) => false
func EqualExportedValuesf ¶
func EqualExportedValuesf(expected interface{}, actual interface{}, msg string, args ...interface{})
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 } assert.EqualExportedValuesf(S{1, 2}, S{1, 3}, "error message %s", "formatted") => true assert.EqualExportedValuesf(S{1, 2}, S{2, 3}, "error message %s", "formatted") => false
func EqualValues ¶
func EqualValues(expected, actual interface{}, msgAndArgs ...interface{})
EqualValues asserts that two objects are equal or convertible to the larger type and equal.
assert.EqualValues(uint32(123), int32(123))
func EqualValuesf ¶
func EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{})
EqualValuesf asserts that two objects are equal or convertible to the larger type and equal.
assert.EqualValuesf(uint32(123), int32(123), "error message %s", "formatted")
func Equalf ¶
func Equalf(expected interface{}, actual interface{}, msg string, args ...interface{})
Equalf asserts that two objects are equal.
assert.Equalf(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 Error ¶
func Error(err error, msgAndArgs ...interface{})
Error asserts that a function returned an error (i.e. not `nil`).
actualObj, err := SomeFunction() if assert.Error(err) { assert.Equal(expectedError, err) }
func ErrorAs ¶
func ErrorAs(err error, target interface{}, msgAndArgs ...interface{})
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.
actualObj, err := SomeFunction() assert.ErrorContains(err, expectedErrorSubString)
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() assert.ErrorContainsf(err, expectedErrorSubString, "error message %s", "formatted")
func ErrorIs ¶
func ErrorIs(err, target error, msgAndArgs ...interface{})
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 assert.Errorf(err, "error message %s", "formatted") { assert.Equal(expectedErrorf, err) }
func Eventually ¶
func Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{})
Eventually asserts that given condition will be met in waitFor time, periodically checking target function each tick.
assert.Eventually(func() bool { return true; }, time.Second, 10*time.Millisecond)
func Eventuallyf ¶
func Eventuallyf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{})
Eventuallyf asserts that given condition will be met in waitFor time, periodically checking target function each tick.
assert.Eventuallyf(func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")
func Exactly ¶
func Exactly(expected, actual interface{}, msgAndArgs ...interface{})
Exactly asserts that two objects are equal in value and type.
assert.Exactly(int32(123), int64(123))
func Exactlyf ¶
func Exactlyf(expected interface{}, actual interface{}, msg string, args ...interface{})
Exactlyf asserts that two objects are equal in value and type.
assert.Exactlyf(int32(123), int64(123), "error message %s", "formatted")
func Fail ¶
func Fail(failureMessage string, msgAndArgs ...interface{})
Fail reports a failure through
func False ¶
func False(value bool, msgAndArgs ...interface{})
False asserts that the specified value is false.
assert.False(myBool)
func Falsef ¶
Falsef asserts that the specified value is false.
assert.Falsef(myBool, "error message %s", "formatted")
func FileExists ¶
func FileExists(path string, msgAndArgs ...interface{})
FileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
func FileExistsf ¶
FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
func Greater ¶
func Greater(e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
Greater asserts that the first element is greater than the second
assert.Greater(2, 1) assert.Greater(float64(2), float64(1)) assert.Greater("b", "a")
func GreaterOrEqual ¶
func GreaterOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
GreaterOrEqual asserts that the first element is greater than or equal to the second
assert.GreaterOrEqual(2, 1) assert.GreaterOrEqual(2, 2) assert.GreaterOrEqual("b", "a") assert.GreaterOrEqual("b", "b")
func GreaterOrEqualf ¶
func GreaterOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{})
GreaterOrEqualf asserts that the first element is greater than or equal to the second
assert.GreaterOrEqualf(2, 1, "error message %s", "formatted") assert.GreaterOrEqualf(2, 2, "error message %s", "formatted") assert.GreaterOrEqualf("b", "a", "error message %s", "formatted") assert.GreaterOrEqualf("b", "b", "error message %s", "formatted")
func Greaterf ¶
func Greaterf(e1 interface{}, e2 interface{}, msg string, args ...interface{})
Greaterf asserts that the first element is greater than the second
assert.Greaterf(2, 1, "error message %s", "formatted") assert.Greaterf(float64(2), float64(1), "error message %s", "formatted") assert.Greaterf("b", "a", "error message %s", "formatted")
func HTTPBody ¶
func HTTPBody(handler http.HandlerFunc, method, url string, values url.Values)
HTTPBody is a helper that returns HTTP body of the response. It returns empty string if building a new request fails.
func HTTPBodyContains ¶
func HTTPBodyContains(handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{})
HTTPBodyContains asserts that a specified handler returns a body that contains a string.
assert.HTTPBodyContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
Returns whether the assertion was successful (true) or not (false).
func HTTPBodyContainsf ¶
func HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{})
HTTPBodyContainsf asserts that a specified handler returns a body that contains a string.
assert.HTTPBodyContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
Returns whether the assertion was successful (true) or not (false).
func HTTPBodyNotContains ¶
func HTTPBodyNotContains(handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{})
HTTPBodyNotContains asserts that a specified handler returns a body that does not contain a string.
assert.HTTPBodyNotContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
Returns whether the assertion was successful (true) or not (false).
func HTTPBodyNotContainsf ¶
func HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{})
HTTPBodyNotContainsf asserts that a specified handler returns a body that does not contain a string.
assert.HTTPBodyNotContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
Returns whether the assertion was successful (true) or not (false).
func HTTPError ¶
func HTTPError(handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{})
HTTPError asserts that a specified handler returns an error status code.
assert.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
Returns whether the assertion was successful (true) or not (false).
func HTTPErrorf ¶
func HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{})
HTTPErrorf asserts that a specified handler returns an error status code.
assert.HTTPErrorf(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
Returns whether the assertion was successful (true) or not (false).
func HTTPRedirect ¶
func HTTPRedirect(handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{})
HTTPRedirect asserts that a specified handler returns a redirect status code.
assert.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
Returns whether the assertion was successful (true) or not (false).
func HTTPRedirectf ¶
func HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{})
HTTPRedirectf asserts that a specified handler returns a redirect status code.
assert.HTTPRedirectf(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
Returns whether the assertion was successful (true) or not (false).
func HTTPStatusCode ¶
func HTTPStatusCode(handler http.HandlerFunc, method, url string, values url.Values, statuscode int, msgAndArgs ...interface{})
HTTPStatusCode asserts that a specified handler returns a specified status code.
assert.HTTPStatusCode(myHandler, "GET", "/notImplemented", nil, 501)
Returns whether the assertion was successful (true) or not (false).
func HTTPStatusCodef ¶
func HTTPStatusCodef(handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{})
HTTPStatusCodef asserts that a specified handler returns a specified status code.
assert.HTTPStatusCodef(myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted")
Returns whether the assertion was successful (true) or not (false).
func HTTPSuccess ¶
func HTTPSuccess(handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{})
HTTPSuccess asserts that a specified handler returns a success status code.
assert.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil)
Returns whether the assertion was successful (true) or not (false).
func HTTPSuccessf ¶
func HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{})
HTTPSuccessf asserts that a specified handler returns a success status code.
assert.HTTPSuccessf(myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")
Returns whether the assertion was successful (true) or not (false).
func Implements ¶
func Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{})
Implements asserts that an object is implemented by the specified interface.
assert.Implements((*MyInterface)(nil), new(MyObject))
func Implementsf ¶
func Implementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{})
Implementsf asserts that an object is implemented by the specified interface.
assert.Implementsf((*MyInterface)(nil), new(MyObject), "error message %s", "formatted")
func InDelta ¶
func InDelta(expected, actual interface{}, delta float64, msgAndArgs ...interface{})
InDelta asserts that the two numerals are within delta of each other.
assert.InDelta(math.Pi, 22/7.0, 0.01)
func InDeltaMapValues ¶
func InDeltaMapValues(expected, actual interface{}, delta float64, msgAndArgs ...interface{})
InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
func InDeltaMapValuesf ¶
func InDeltaMapValuesf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{})
InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
func InDeltaSlice ¶
func InDeltaSlice(expected, actual interface{}, delta float64, msgAndArgs ...interface{})
InDeltaSlice is the same as InDelta, except it compares two slices.
func InDeltaSlicef ¶
func InDeltaSlicef(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{})
InDeltaSlicef is the same as InDelta, except it compares two slices.
func InDeltaf ¶
func InDeltaf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{})
InDeltaf asserts that the two numerals are within delta of each other.
assert.InDeltaf(math.Pi, 22/7.0, 0.01, "error message %s", "formatted")
func InEpsilon ¶
func InEpsilon(expected, actual interface{}, epsilon float64, msgAndArgs ...interface{})
InEpsilon asserts that expected and actual have a relative error less than epsilon
func InEpsilonSlice ¶
func InEpsilonSlice(expected, actual interface{}, epsilon float64, msgAndArgs ...interface{})
InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
func InEpsilonSlicef ¶
func InEpsilonSlicef(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{})
InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.
func InEpsilonf ¶
func InEpsilonf(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{})
InEpsilonf asserts that expected and actual have a relative error less than epsilon
func IsDecreasing ¶
func IsDecreasing(object interface{}, msgAndArgs ...interface{})
IsDecreasing asserts that the collection is decreasing
assert.IsDecreasing([]int{2, 1, 0}) assert.IsDecreasing([]float{2, 1}) assert.IsDecreasing([]string{"b", "a"})
func IsDecreasingf ¶
func IsDecreasingf(object interface{}, msg string, args ...interface{})
IsDecreasingf asserts that the collection is decreasing
assert.IsDecreasingf([]int{2, 1, 0}, "error message %s", "formatted") assert.IsDecreasingf([]float{2, 1}, "error message %s", "formatted") assert.IsDecreasingf([]string{"b", "a"}, "error message %s", "formatted")
func IsIncreasing ¶
func IsIncreasing(object interface{}, msgAndArgs ...interface{})
IsIncreasing asserts that the collection is increasing
assert.IsIncreasing([]int{1, 2, 3}) assert.IsIncreasing([]float{1, 2}) assert.IsIncreasing([]string{"a", "b"})
func IsIncreasingf ¶
func IsIncreasingf(object interface{}, msg string, args ...interface{})
IsIncreasingf asserts that the collection is increasing
assert.IsIncreasingf([]int{1, 2, 3}, "error message %s", "formatted") assert.IsIncreasingf([]float{1, 2}, "error message %s", "formatted") assert.IsIncreasingf([]string{"a", "b"}, "error message %s", "formatted")
func IsNonDecreasing ¶
func IsNonDecreasing(object interface{}, msgAndArgs ...interface{})
IsNonDecreasing asserts that the collection is not decreasing
assert.IsNonDecreasing([]int{1, 1, 2}) assert.IsNonDecreasing([]float{1, 2}) assert.IsNonDecreasing([]string{"a", "b"})
func IsNonDecreasingf ¶
func IsNonDecreasingf(object interface{}, msg string, args ...interface{})
IsNonDecreasingf asserts that the collection is not decreasing
assert.IsNonDecreasingf([]int{1, 1, 2}, "error message %s", "formatted") assert.IsNonDecreasingf([]float{1, 2}, "error message %s", "formatted") assert.IsNonDecreasingf([]string{"a", "b"}, "error message %s", "formatted")
func IsNonIncreasing ¶
func IsNonIncreasing(object interface{}, msgAndArgs ...interface{})
IsNonIncreasing asserts that the collection is not increasing
assert.IsNonIncreasing([]int{2, 1, 1}) assert.IsNonIncreasing([]float{2, 1}) assert.IsNonIncreasing([]string{"b", "a"})
func IsNonIncreasingf ¶
func IsNonIncreasingf(object interface{}, msg string, args ...interface{})
IsNonIncreasingf asserts that the collection is not increasing
assert.IsNonIncreasingf([]int{2, 1, 1}, "error message %s", "formatted") assert.IsNonIncreasingf([]float{2, 1}, "error message %s", "formatted") assert.IsNonIncreasingf([]string{"b", "a"}, "error message %s", "formatted")
func IsType ¶
func IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{})
IsType asserts that the specified objects are of the same type.
func IsTypef ¶
func IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{})
IsTypef asserts that the specified objects are of the same type.
func JSONEq ¶
JSONEq asserts that two JSON strings are equivalent.
assert.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
func JSONEqf ¶
JSONEqf asserts that two JSON strings are equivalent.
assert.JSONEqf(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")
func Len ¶
func Len(object interface{}, length int, msgAndArgs ...interface{})
Len asserts that the specified object has specific length. Len also fails if the object has a type that len() not accept.
assert.Len(mySlice, 3)
func Lenf ¶
Lenf asserts that the specified object has specific length. Lenf also fails if the object has a type that len() not accept.
assert.Lenf(mySlice, 3, "error message %s", "formatted")
func Less ¶
func Less(e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
Less asserts that the first element is less than the second
assert.Less(1, 2) assert.Less(float64(1), float64(2)) assert.Less("a", "b")
func LessOrEqual ¶
func LessOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
LessOrEqual asserts that the first element is less than or equal to the second
assert.LessOrEqual(1, 2) assert.LessOrEqual(2, 2) assert.LessOrEqual("a", "b") assert.LessOrEqual("b", "b")
func LessOrEqualf ¶
func LessOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{})
LessOrEqualf asserts that the first element is less than or equal to the second
assert.LessOrEqualf(1, 2, "error message %s", "formatted") assert.LessOrEqualf(2, 2, "error message %s", "formatted") assert.LessOrEqualf("a", "b", "error message %s", "formatted") assert.LessOrEqualf("b", "b", "error message %s", "formatted")
func Lessf ¶
func Lessf(e1 interface{}, e2 interface{}, msg string, args ...interface{})
Lessf asserts that the first element is less than the second
assert.Lessf(1, 2, "error message %s", "formatted") assert.Lessf(float64(1), float64(2), "error message %s", "formatted") assert.Lessf("a", "b", "error message %s", "formatted")
func Locked ¶ added in v0.4.0
Locked asserts that the TryLocker is already locked.
assert.IsDecreasing([]int{2, 1, 0}) assert.IsDecreasing([]float{2, 1}) assert.IsDecreasing([]string{"b", "a"})
func Lockedf ¶ added in v0.4.0
Lockedf asserts that the TryLocker is already locked.
assert.IsDecreasing([]int{2, 1, 0}) assert.IsDecreasing([]float{2, 1}) assert.IsDecreasing([]string{"b", "a"})
func Negative ¶
func Negative(e interface{}, msgAndArgs ...interface{})
Negative asserts that the specified element is negative
assert.Negative(-1) assert.Negative(-1.23)
func Negativef ¶
func Negativef(e interface{}, msg string, args ...interface{})
Negativef asserts that the specified element is negative
assert.Negativef(-1, "error message %s", "formatted") assert.Negativef(-1.23, "error message %s", "formatted")
func Never ¶
func Never(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{})
Never asserts that the given condition doesn't satisfy in waitFor time, periodically checking the target function each tick.
assert.Never(func() bool { return false; }, time.Second, 10*time.Millisecond)
func Neverf ¶
func Neverf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{})
Neverf asserts that the given condition doesn't satisfy in waitFor time, periodically checking the target function each tick.
assert.Neverf(func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")
func Nil ¶
func Nil(object interface{}, msgAndArgs ...interface{})
Nil asserts that the specified object is nil.
assert.Nil(err)
func Nilf ¶
func Nilf(object interface{}, msg string, args ...interface{})
Nilf asserts that the specified object is nil.
assert.Nilf(err, "error message %s", "formatted")
func NoDirExists ¶
func NoDirExists(path string, msgAndArgs ...interface{})
NoDirExists checks whether a directory does not exist in the given path. It fails if the path points to an existing _directory_ only.
func NoDirExistsf ¶
NoDirExistsf checks whether a directory does not exist in the given path. It fails if the path points to an existing _directory_ only.
func NoError ¶
func NoError(err error, msgAndArgs ...interface{})
NoError asserts that a function returned no error (i.e. `nil`).
actualObj, err := SomeFunction() if assert.NoError(err) { assert.Equal(expectedObj, actualObj) }
func NoErrorf ¶
NoErrorf asserts that a function returned no error (i.e. `nil`).
actualObj, err := SomeFunction() if assert.NoErrorf(err, "error message %s", "formatted") { assert.Equal(expectedObj, actualObj) }
func NoFileExists ¶
func NoFileExists(path string, msgAndArgs ...interface{})
NoFileExists checks whether a file does not exist in a given path. It fails if the path points to an existing _file_ only.
func NoFileExistsf ¶
NoFileExistsf checks whether a file does not exist in a given path. It fails if the path points to an existing _file_ only.
func NotContains ¶
func NotContains(s, contains interface{}, msgAndArgs ...interface{})
NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.
assert.NotContains("Hello World", "Earth") assert.NotContains(["Hello", "World"], "Earth") assert.NotContains({"Hello": "World"}, "Earth")
func NotContainsf ¶
func NotContainsf(s interface{}, contains interface{}, msg string, args ...interface{})
NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.
assert.NotContainsf("Hello World", "Earth", "error message %s", "formatted") assert.NotContainsf(["Hello", "World"], "Earth", "error message %s", "formatted") assert.NotContainsf({"Hello": "World"}, "Earth", "error message %s", "formatted")
func NotElementsMatch ¶ added in v0.5.0
func NotElementsMatch(listA, listB interface{}, msgAndArgs ...interface{})
NotElementsMatch asserts that the specified listA(array, slice...) is NOT equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should not match. This is an inverse of ElementsMatch.
assert.NotElementsMatch([1, 1, 2, 3], [1, 1, 2, 3]) -> false
assert.NotElementsMatch([1, 1, 2, 3], [1, 2, 3]) -> true
assert.NotElementsMatch([1, 2, 3], [1, 2, 4]) -> true
func NotElementsMatchf ¶ added in v0.5.0
func NotElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{})
NotElementsMatchf asserts that the specified listA(array, slice...) is NOT equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should not match. This is an inverse of ElementsMatch.
assert.NotElementsMatchf([1, 1, 2, 3], [1, 1, 2, 3], "error message %s", "formatted") -> false
assert.NotElementsMatchf([1, 1, 2, 3], [1, 2, 3], "error message %s", "formatted") -> true
assert.NotElementsMatchf([1, 2, 3], [1, 2, 4], "error message %s", "formatted") -> true
func NotEmpty ¶
func NotEmpty(object interface{}, msgAndArgs ...interface{})
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 assert.NotEmpty(obj) { assert.Equal("two", obj[1]) }
func NotEmptyf ¶
func NotEmptyf(object interface{}, msg string, args ...interface{})
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 assert.NotEmptyf(obj, "error message %s", "formatted") { assert.Equal("two", obj[1]) }
func NotEqual ¶
func NotEqual(expected, actual interface{}, msgAndArgs ...interface{})
NotEqual asserts that the specified values are NOT equal.
assert.NotEqual(obj1, obj2)
Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses).
func NotEqualValues ¶
func NotEqualValues(expected, actual interface{}, msgAndArgs ...interface{})
NotEqualValues asserts that two objects are not equal even when converted to the same type
assert.NotEqualValues(obj1, obj2)
func NotEqualValuesf ¶
func NotEqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{})
NotEqualValuesf asserts that two objects are not equal even when converted to the same type
assert.NotEqualValuesf(obj1, obj2, "error message %s", "formatted")
func NotEqualf ¶
func NotEqualf(expected interface{}, actual interface{}, msg string, args ...interface{})
NotEqualf asserts that the specified values are NOT equal.
assert.NotEqualf(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 v0.5.0
func NotErrorAs(err error, target interface{}, msgAndArgs ...interface{})
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 v0.5.0
NotErrorAsf asserts that none of the errors in err's chain matches target, but if so, sets target to that error value.
func NotErrorIs ¶
func NotErrorIs(err, target error, msgAndArgs ...interface{})
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 NotImplements ¶ added in v0.2.0
func NotImplements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{})
NotImplements asserts that an object does not implement the specified interface.
assert.NotImplements((*MyInterface)(nil), new(MyObject))
func NotImplementsf ¶ added in v0.2.0
func NotImplementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{})
NotImplementsf asserts that an object does not implement the specified interface.
assert.NotImplementsf((*MyInterface)(nil), new(MyObject), "error message %s", "formatted")
func NotNil ¶
func NotNil(object interface{}, msgAndArgs ...interface{})
NotNil asserts that the specified object is not nil.
assert.NotNil(err)
func NotNilf ¶
func NotNilf(object interface{}, msg string, args ...interface{})
NotNilf asserts that the specified object is not nil.
assert.NotNilf(err, "error message %s", "formatted")
func NotPanics ¶
func NotPanics(f PanicTestFunc, msgAndArgs ...interface{})
NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
assert.NotPanics(func(){ RemainCalm() })
func NotPanicsf ¶
func NotPanicsf(f PanicTestFunc, msg string, args ...interface{})
NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
assert.NotPanicsf(func(){ RemainCalm() }, "error message %s", "formatted")
func NotRegexp ¶
func NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{})
NotRegexp asserts that a specified regexp does not match a string.
assert.NotRegexp(regexp.MustCompile("starts"), "it's starting") assert.NotRegexp("^start", "it's not starting")
func NotRegexpf ¶
func NotRegexpf(rx interface{}, str interface{}, msg string, args ...interface{})
NotRegexpf asserts that a specified regexp does not match a string.
assert.NotRegexpf(regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted") assert.NotRegexpf("^start", "it's not starting", "error message %s", "formatted")
func NotSame ¶
func NotSame(expected, actual interface{}, msgAndArgs ...interface{})
NotSame asserts that two pointers do not reference the same object.
assert.NotSame(ptr1, ptr2)
Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.
func NotSamef ¶
func NotSamef(expected interface{}, actual interface{}, msg string, args ...interface{})
NotSamef asserts that two pointers do not reference the same object.
assert.NotSamef(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 ¶
func NotSubset(list, subset interface{}, msgAndArgs ...interface{})
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.
assert.NotSubset([1, 3, 4], [1, 2]) assert.NotSubset({"x": 1, "y": 2}, {"z": 3})
func NotSubsetf ¶
func NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{})
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.
assert.NotSubsetf([1, 3, 4], [1, 2], "error message %s", "formatted") assert.NotSubsetf({"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
func NotZero ¶
func NotZero(i interface{}, msgAndArgs ...interface{})
NotZero asserts that i is not the zero value for its type.
func NotZerof ¶
func NotZerof(i interface{}, msg string, args ...interface{})
NotZerof asserts that i is not the zero value for its type.
func ObjectsAreEqual ¶
func ObjectsAreEqual(expected, actual interface{})
ObjectsAreEqual determines if two objects are considered equal.
This function does no assertion of any kind.
func ObjectsAreEqualValues ¶
func ObjectsAreEqualValues(expected, actual interface{})
ObjectsAreEqualValues gets whether two objects are equal, or if their values are equal.
func ObjectsExportedFieldsAreEqual
deprecated
func ObjectsExportedFieldsAreEqual(expected, actual interface{})
ObjectsExportedFieldsAreEqual determines if the exported (public) fields of two objects are considered equal. This comparison of only exported fields is applied recursively to nested data structures.
This function does no assertion of any kind.
Deprecated: Use EqualExportedValues instead.
func Panics ¶
func Panics(f PanicTestFunc, msgAndArgs ...interface{})
Panics asserts that the code inside the specified PanicTestFunc panics.
assert.Panics(func(){ GoCrazy() })
func PanicsWithError ¶
func PanicsWithError(errString string, f PanicTestFunc, msgAndArgs ...interface{})
PanicsWithError asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value is an error that satisfies the EqualError comparison.
assert.PanicsWithError("crazy error", func(){ GoCrazy() })
func PanicsWithErrorf ¶
func PanicsWithErrorf(errString string, f PanicTestFunc, msg string, args ...interface{})
PanicsWithErrorf asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value is an error that satisfies the EqualError comparison.
assert.PanicsWithErrorf("crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
func PanicsWithValue ¶
func PanicsWithValue(expected interface{}, f PanicTestFunc, msgAndArgs ...interface{})
PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value equals the expected panic value.
assert.PanicsWithValue("crazy error", func(){ GoCrazy() })
func PanicsWithValuef ¶
func PanicsWithValuef(expected interface{}, f PanicTestFunc, msg string, args ...interface{})
PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value equals the expected panic value.
assert.PanicsWithValuef("crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
func Panicsf ¶
func Panicsf(f PanicTestFunc, msg string, args ...interface{})
Panicsf asserts that the code inside the specified PanicTestFunc panics.
assert.Panicsf(func(){ GoCrazy() }, "error message %s", "formatted")
func Positive ¶
func Positive(e interface{}, msgAndArgs ...interface{})
Positive asserts that the specified element is positive
assert.Positive(1) assert.Positive(1.23)
func Positivef ¶
func Positivef(e interface{}, msg string, args ...interface{})
Positivef asserts that the specified element is positive
assert.Positivef(1, "error message %s", "formatted") assert.Positivef(1.23, "error message %s", "formatted")
func Regexp ¶
func Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{})
Regexp asserts that a specified regexp matches a string.
assert.Regexp(regexp.MustCompile("start"), "it's starting") assert.Regexp("start...$", "it's not starting")
func Regexpf ¶
func Regexpf(rx interface{}, str interface{}, msg string, args ...interface{})
Regexpf asserts that a specified regexp matches a string.
assert.Regexpf(regexp.MustCompile("start"), "it's starting", "error message %s", "formatted") assert.Regexpf("start...$", "it's not starting", "error message %s", "formatted")
func Same ¶
func Same(expected, actual interface{}, msgAndArgs ...interface{})
Same asserts that two pointers reference the same object.
assert.Same(ptr1, ptr2)
Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.
func Samef ¶
func Samef(expected interface{}, actual interface{}, msg string, args ...interface{})
Samef asserts that two pointers reference the same object.
assert.Samef(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 ¶
func Subset(list, subset interface{}, msgAndArgs ...interface{})
Subset asserts that the specified list(array, slice...) or map contains all elements given in the specified subset list(array, slice...) or map.
assert.Subset([1, 2, 3], [1, 2]) assert.Subset({"x": 1, "y": 2}, {"x": 1})
func Subsetf ¶
func Subsetf(list interface{}, subset interface{}, msg string, args ...interface{})
Subsetf asserts that the specified list(array, slice...) or map contains all elements given in the specified subset list(array, slice...) or map.
assert.Subsetf([1, 2, 3], [1, 2], "error message %s", "formatted") assert.Subsetf({"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
func True ¶
func True(value bool, msgAndArgs ...interface{})
True asserts that the specified value is true.
assert.True(myBool)
func Truef ¶
Truef asserts that the specified value is true.
assert.Truef(myBool, "error message %s", "formatted")
func Unlocked ¶ added in v0.5.0
Unlocked asserts that the TryLocker is unlocked.
assert.IsDecreasing([]int{2, 1, 0}) assert.IsDecreasing([]float{2, 1}) assert.IsDecreasing([]string{"b", "a"})
func Unlockedf ¶ added in v0.5.0
UnLockedf asserts that the TryLocker is unlocked.
assert.IsDecreasing([]int{2, 1, 0}) assert.IsDecreasing([]float{2, 1}) assert.IsDecreasing([]string{"b", "a"})
func WithinDuration ¶
WithinDuration asserts that the two times are within duration delta of each other.
assert.WithinDuration(time.Now(), time.Now(), 10*time.Second)
func WithinDurationf ¶
func WithinDurationf(expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{})
WithinDurationf asserts that the two times are within duration delta of each other.
assert.WithinDurationf(time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
func WithinRange ¶
WithinRange asserts that a time is within a time range (inclusive).
assert.WithinRange(time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second))
func WithinRangef ¶
func WithinRangef(actual time.Time, start time.Time, end time.Time, msg string, args ...interface{})
WithinRangef asserts that a time is within a time range (inclusive).
assert.WithinRangef(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 CollectT ¶
type CollectT struct {
// contains filtered or unexported fields
}
CollectT implements the TestingT interface and collects all errors.
type CompareType
deprecated
type CompareType = compareResult
Deprecated: CompareType has only ever been for internal use and has accidentally been published since v1.6.0. Do not use it.
type Comparison ¶
type Comparison func() (success bool)
Comparison is a custom function that returns true on success and false on failure
type ComparisonAssertionFunc ¶
type ComparisonAssertionFunc func(interface{}, interface{}, ...interface{}) bool
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 ¶ added in v0.5.0
type PanicAssertionFunc = func(f PanicTestFunc, msgAndArgs ...interface{}) bool
PanicAssertionFunc is a common function prototype when validating a panic value. Can be useful for table driven tests.
type PanicTestFunc ¶
type PanicTestFunc func()
PanicTestFunc defines a func that should be passed to the assert.Panics and assert.NotPanics methods, and represents a simple func that takes no arguments, and returns nothing.
type TestingT ¶
type TestingT interface {
Errorf(format string, args ...interface{})
}
TestingT is an interface wrapper around *testing.T
type TryLocker ¶ added in v0.4.0
A TryLocker represents an object that can attempt to acquire a lock and report whether it succeeded.
sync.Mutex and sync.RWMutex implements this interface.
type ValueAssertionFunc ¶
type ValueAssertionFunc func(interface{}, ...interface{}) bool
ValueAssertionFunc is a common function prototype when validating a single value. Can be useful for table driven tests.