Documentation ¶
Overview ¶
Package assert simplifies writing test assertions.
Output will contain a helpful diff rendered using as well as the source code of the expression being tested. For example, if you call assert.Equal(t, car.Name, "Porsche"), the error message will include "car.Name".
Additional options and custom comparators can be registered using RegisterOptions, or passed in as the last parameter to the function call. For example, to indicate that unexported fields should be ignored on MyType, you can use:
assert.RegisterOptions( cmpopts.IgnoreUnexported(MyType{}), )
See the go-cmp docs for more options: https://godoc.org/github.com/google/go-cmp/cmp.
Index ¶
- func Contains(t testingT, got, want string) bool
- func Empty(t testingT, got interface{}) bool
- func Equal(t testingT, got, want interface{}, opts ...cmp.Option) bool
- func ErrorContains(t testingT, got error, want string) bool
- func False(t testingT, got bool) bool
- func Ignore(paths ...string) cmp.Option
- func JSONEqual(t testingT, got, want interface{}, opts ...cmp.Option) bool
- func JSONLookup(t testingT, subject interface{}, path string) interface{}
- func JSONPath(t testingT, subject interface{}, path string, want interface{}, ...) bool
- func Match(t testingT, got, want string) bool
- func Must(t testingT, err error)
- func Nil(t testingT, got interface{}) bool
- func NotEmpty(t testingT, got interface{}) bool
- func NotEqual(t testingT, got, want interface{}, opts ...cmp.Option) bool
- func NotNil(t testingT, got interface{}) bool
- func RegisterOptions(opts ...cmp.Option)
- func True(t testingT, got bool) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorContains ¶
ErrorContains asserts that the error message contains the wanted string.
func Ignore ¶
Ignore configures assert to ignore the specified field paths when testing equality. Nested paths may be expressed with periods (e.g. "User.ID").
func JSONEqual ¶
JSONEqual asserts that got and want are equal when represented as JSON. If either are already strings, they will be considered raw JSON. Otherwise, they will be marshaled to JSON before comparison.
func JSONLookup ¶
func JSONLookup(t testingT, subject interface{}, path string) interface{}
JSONLookup fetches a value from a JSON object using the path expression.
func JSONPath ¶
func JSONPath(t testingT, subject interface{}, path string, want interface{}, opts ...cmp.Option) bool
JSONPath asserts that evaluating the path expression against the subject results in want. The subject and want parameters are both converted to their JSON representation before being evaluated.
func Must ¶
func Must(t testingT, err error)
Must asserts that err is nil, calling t.Fatal otherwise.
func NotEmpty ¶
func NotEmpty(t testingT, got interface{}) bool
NotEmpty asserts that got is not empty.
func RegisterOptions ¶
RegisterOptions registers a default option for all tests in the current package. It's intended to be used in an init function, like:
func init() { assert.RegisterOptions( cmp.Comparer(func(x, y *Thing) bool { return x.ID == y.ID }), ) }
Note that due to how "go test" operates, these options will not leak between packages.
Types ¶
This section is empty.