Documentation ¶
Overview ¶
Package assert provides value assertions.
Index ¶
- Variables
- func RegisterCustomEqualer(eq Equaler)
- type Assertion
- func And(assertions ...Assertion) Assertion
- func Build(expect interface{}) Assertion
- func Contains(assertion Assertion) Assertion
- func Equal(expected interface{}) Assertion
- func Greater(expected interface{}) Assertion
- func GreaterOrEqual(expected interface{}) Assertion
- func Length(expected interface{}) Assertion
- func Less(expected interface{}) Assertion
- func LessOrEqual(expected interface{}) Assertion
- func NotContains(assertion Assertion) Assertion
- func NotZero() Assertion
- func Or(assertions ...Assertion) Assertion
- func Regexp(expr string) Assertion
- type AssertionFunc
- type Equaler
- type Error
Constants ¶
This section is empty.
Variables ¶
var AppendError = multierror.Append
AppendError is a helper function that will append more errors onto an Error in order to create a larger multi-error.
Functions ¶
func RegisterCustomEqualer ¶
func RegisterCustomEqualer(eq Equaler)
RegisterCustomEqualer appends eq as a custom equaler. Registered equaler will be used when all default equalers judge two values are not equal.
Types ¶
type Assertion ¶
type Assertion interface {
Assert(v interface{}) error
}
Assertion implements value assertion.
func And ¶
And returns a new assertion to ensure that value passes all assertions. If the assertions are empty, it returns an error.
func Equal ¶
func Equal(expected interface{}) Assertion
Equal returns an assertion to ensure a value equals the expected value.
func Greater ¶
func Greater(expected interface{}) Assertion
Greater returns an assertion to ensure a value greater than the expected value.
func GreaterOrEqual ¶
func GreaterOrEqual(expected interface{}) Assertion
GreaterOrEqual returns an assertion to ensure a value equal or greater than the expected value.
func Length ¶
func Length(expected interface{}) Assertion
Length returns an assertion to ensure a value length is the expected value.
func Less ¶
func Less(expected interface{}) Assertion
Less returns an assertion to ensure a value less than the expected value.
func LessOrEqual ¶
func LessOrEqual(expected interface{}) Assertion
LessOrEqual returns an assertion to ensure a value equal or less than the expected value.
func NotContains ¶
NotContains returns an assertion to ensure a value doesn't contain the value.
func NotZero ¶
func NotZero() Assertion
NotZero returns an assertion to ensure a value is not zero value.
type AssertionFunc ¶
type AssertionFunc func(v interface{}) error
AssertionFunc is an adaptor to allow the use of ordinary functions as assertions.
func (AssertionFunc) Assert ¶
func (f AssertionFunc) Assert(v interface{}) error
Assert asserts the v.
type Equaler ¶
type Equaler interface { // Equal checks two values are equal or not. // If the ok is true, the err should be used as result. Equal(expected, got interface{}) (ok bool, err error) }
Equaler is the interface for custom equaler.
func EqualerFunc ¶
EqualerFunc is an adaptor to allow the use of ordinary functions as Equaler.