Documentation ¶
Overview ¶
Package assert provides convenience assert methods to complement the built in go testing library. It's intended to add onto standard Go tests. Example usage:
func TestSomething(t *testing.T) { i, err := doSomething() assert.NoErr(t, err) assert.Equal(t, i, 123, "returned integer") }
Index ¶
- func Equal(t Tester, actual, expected interface{}, noun string)
- func Err(t Tester, expected error, actual error)
- func ExistsErr(t Tester, err error, noun string)
- func False(t Tester, b bool, fmtStr string, vals ...interface{})
- func Nil(t Tester, i interface{}, noun string)
- func NoErr(t Tester, e error)
- func NotNil(t Tester, i interface{}, noun string)
- func True(t Tester, b bool, fmtStr string, vals ...interface{})
- type Equaler
- type Tester
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Equal ¶
Equal ensures that the actual value returned from a test was equal to an expected. it uses reflect.DeepEqual to do so. name is used to describe the values being compared. it's used in the error string if actual != expected.
func Err ¶
Err calls t.Fatalf if expected is not equal to actual. it uses reflect.DeepEqual to determine if the errors are equal
func ExistsErr ¶
ExistsErr calls t.Fatalf if err == nil. The message will explain that the error described by noun was nil when it shouldn't have been
func Nil ¶
Nil uses reflect.DeepEqual(i, nil) to determine if i is nil. if it's not, Nil calls t.Fatalf explaining that the noun i is not nil when it should have been
Types ¶
type Equaler ¶
Equaler determines if a type is equal to any other type that conforms to Equaler. All types passed to assert.Equal are checked to see if they conform to this interface, and if they do, their Equal function is called to check for their equality. This call is made instead of the call to reflect.DeepEqual
type Tester ¶
type Tester interface {
Fatalf(string, ...interface{})
}
Tester is a stub interface that *testing.T conforms to. It is used in all exported function calls in this assert library so that the library can be tested, or a caller can use a custom testing library. As said before, however, the most widely used implementation of this interface will be *testing.T. Example usage:
func TestSomething(t *testing.T) { assert.Equal(t, "something", "something", "something") }
func WithFrameWrapper ¶
WithFrameWrapper returns the original Tester, wrapped by a frameWrapper that adds context about how many frames to backtrack on the call stack when identifying the source of a failed assertion. If the Tester passed in is already a frameWrapper, the Tester wrapped by that frameWrapper is unwrapped and re-wrapped with updated context.