Documentation ¶
Overview ¶
Package massert implements an assertion framework which is useful in tests.
Index ¶
- func Assert(t *testing.T, aa ...Assertion)
- func Require(t *testing.T, aa ...Assertion)
- type AssertErr
- type Assertion
- func All(aa ...Assertion) Assertion
- func Any(aa ...Assertion) Assertion
- func AnyOne(aa ...Assertion) Assertion
- func Comment(a Assertion, msg string, args ...interface{}) Assertion
- func Equal(a, b interface{}) Assertion
- func Error(err error) Assertion
- func Errorf(str string, args ...interface{}) Assertion
- func HasKey(set, elem interface{}) Assertion
- func HasValue(set, elem interface{}) Assertion
- func Length(set interface{}, length int) Assertion
- func Nil(i interface{}) Assertion
- func None(aa ...Assertion) Assertion
- func Not(a Assertion) Assertion
- func Subset(set, subset interface{}) Assertion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AssertErr ¶
type AssertErr struct { Err error // The error which occurred Assertion Assertion // The Assertion which failed }
AssertErr is an error returned by Assertions which have failed, containing information about both the reason for failure and the Assertion itself.
type Assertion ¶
type Assertion interface { Assert() error Description() string // A description of the Assertion // Returns the callstack of where the Assertion was created, ordered from // closest to farthest. This may not necessarily contain the entire // callstack if that would be inconveniently cumbersome. Stack() []runtime.Frame }
Assertion is an entity which will make some kind of assertion and produce an error if that assertion does not hold true. The error returned will generally be of type AssertErr.
func All ¶
All asserts that at all of the given Assertions succeed. Its Assert method will return the error of whichever Assertion failed.
func Equal ¶
func Equal(a, b interface{}) Assertion
Equal asserts that the two values are exactly equal, and uses the reflect.DeepEqual function to determine if they are.
func HasKey ¶
func HasKey(set, elem interface{}) Assertion
HasKey asserts that the given set (which must be a map type) has the given element as a key in it.
func HasValue ¶
func HasValue(set, elem interface{}) Assertion
HasValue asserts that the given set has the given element as a value in it. The set may be an array, a slice, or a map, and if it's a map then the elem will need to be a value in it.
func Length ¶
Length asserts that the given set has the given number of elements in it. The set may be an array, a slice, or a map. A nil value'd set is considered to be a length of zero.
func Nil ¶
func Nil(i interface{}) Assertion
Nil asserts that the value is nil. This assertion works both if the value is the untyped nil value (e.g. `Nil(nil)`) or if it's a typed nil value (e.g. `Nil([]byte(nil))`).
func None ¶
None asserts that all of the given Assertions fail.
NOTE this is functionally equivalent to doing `Not(Any(aa...))`, but the error returned is more helpful.