Documentation
¶
Overview ¶
Package assert is a minimal Go test package.
Index ¶
- Variables
- func Equal[T any](t TestingT, got, want T, msg ...string)
- func Error(t TestingT, got error, want any, msg ...string)
- func False(t TestingT, got bool, msg ...string)
- func MatchesRegex(t TestingT, got, pattern string, msg ...string)
- func Nil(t TestingT, got any, msg ...string)
- func NotEqual[T any](t TestingT, got, want T, msg ...string)
- func NotNil(t TestingT, got any, msg ...string)
- func True(t TestingT, got bool, msg ...string)
- type TestingT
Constants ¶
This section is empty.
Variables ¶
var Assert = True
Assert is an alias for True
Functions ¶
func Error ¶
Error fails assertion if got and want are not "error similar". want can be one of: nil, a string, an error, or an interface.
Some examples...
assert that an error value matches (string match)
assert.Error(t, err, "my bad error")
assert error value matches (error match)
assert.Error(t, err, err2)
assert that an error value matches, which works with wrapped errors, using errors.Is under the hood
wrappedErr := fmt.Errorf("wrapped: %w", err)
assert.Error(t, err, wrappedErr)
can also check for error type, using errors.As under the hood
assert.Error(t, err, reflect.TypeFor[*fs.PathError]())
func MatchesRegex ¶
MatchesRegex asserts that the string matches the regex pattern.
Example
assert.MatchesRegexp(t, "abc123d", `abc[123]+$`)
