Documentation ¶
Index ¶
- type Equaler
- type Is
- func (is *Is) AddMsg(format string, args ...interface{}) *Is
- func (is *Is) Equal(actual interface{}, expected interface{})
- func (is *Is) EqualType(expected, actual interface{})
- func (is *Is) Err(e error)
- func (is *Is) False(b bool)
- func (is *Is) Lax() *Is
- func (is *Is) Len(o interface{}, l int)
- func (is *Is) Msg(format string, args ...interface{}) *Is
- func (is *Is) New(tb testing.TB) *Is
- func (is *Is) Nil(o interface{})
- func (is *Is) NotEqual(a interface{}, b interface{})
- func (is *Is) NotErr(e error)
- func (is *Is) NotNil(o interface{})
- func (is *Is) NotOneOf(a interface{}, b ...interface{})
- func (is *Is) NotZero(o interface{})
- func (is *Is) OneOf(a interface{}, b ...interface{})
- func (is *Is) ShouldPanic(f func())
- func (is *Is) Strict() *Is
- func (is *Is) True(b bool)
- func (is *Is) WaitForTrue(timeout time.Duration, f func() bool)
- func (is *Is) Zero(o interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Equaler ¶
type Equaler interface {
Equal(in interface{}) bool
}
Equaler is used to define equality for types.
For example, this is useful if you have a struct that includes time.Time fields. You can implement this method and use time.Time.Equal() to do the comparison.
type Is ¶
Is provides methods that leverage the existing testing capabilities found in the Go test framework. The methods provided allow for a more natural, efficient and expressive approach to writing tests. The goal is to write fewer lines of code while improving communication of intent.
func New ¶
New creates a new instance of the Is object and stores a reference to the provided testing object.
func (*Is) AddMsg ¶
AddMsg appends a message to print in the event of a failure. This allows you to build a failure message in multiple steps. If no message was previously set, simply sets the message.
This method is most useful as a way of setting a default error message, then adding additional information to the output for specific assertions. For example:
is := is.New(t).Msg("User ID: %d",u.ID) /*do things*/ is.AddMsg("Raw Response: %s",body).Equal(res.StatusCode, http.StatusCreated)
func (*Is) Equal ¶
func (is *Is) Equal(actual interface{}, expected interface{})
Equal performs a deep compare of the provided objects and fails if they are not equal.
Equal does not respect type differences. If the types are different and comparable (eg int32 and int64), they will be compared as though they are the same type.
func (*Is) EqualType ¶
func (is *Is) EqualType(expected, actual interface{})
EqualType checks the type of the two provided objects and fails if they are not the same.
func (*Is) Lax ¶ added in v1.1.1
Lax returns a copy of this instance of Is which does not abort the test if a failure occurs. Use this to run a set of tests and see all the failures at once.
func (*Is) Len ¶
Len checks the provided object to determine if it is the same length as the provided length argument.
If the object is not one of type array, slice or map, it will fail.
func (*Is) Msg ¶
Msg defines a message to print in the event of a failure. This allows you to print out additional information about a failure if it happens.
func (*Is) New ¶
New creates a new copy of your Is object and replaces the internal testing object with the provided testing object. This is useful for re-initializing your `is` instance inside a subtest so that it doesn't panic when using Strict mode.
For example, creating your initial instance as such
is := is.New(t)
is the convention, but this obviously shadows the `is` package namespace. Inside your subtest, you can do the exact same thing to initialize a locally scoped variable that uses the subtest's testing.T object.
func (*Is) Nil ¶
func (is *Is) Nil(o interface{})
Nil checks the provided object to determine if it is nil.
func (*Is) NotEqual ¶
func (is *Is) NotEqual(a interface{}, b interface{})
NotEqual performs a deep compare of the provided objects and fails if they are equal.
NotEqual does not respect type differences. If the types are different and comparable (eg int32 and int64), they will be compared as though they are the same type.
func (*Is) NotErr ¶
NotErr checks the provided error object to determine if an error is not present.
func (*Is) NotNil ¶
func (is *Is) NotNil(o interface{})
NotNil checks the provided object to determine if it is not nil.
func (*Is) NotOneOf ¶
func (is *Is) NotOneOf(a interface{}, b ...interface{})
NotOneOf performs a deep compare of the provided object and an array of comparison objects. It fails if the first object is equal to one of the comparison objects.
NotOneOf does not respect type differences. If the types are different and comparable (eg int32 and int64), they will be compared as though they are the same type.
func (*Is) NotZero ¶
func (is *Is) NotZero(o interface{})
NotZero checks the provided object to determine if it is not the zero value for the type of that object. The zero value is the same as what the object would contain when initialized but not assigned.
This method, for example, would be used to determine if a string is not empty, an array is not empty or a map is not empty. It could also be used to determine if a number is not 0.
In cases such as slice, map, array and chan, a nil value is treated the same as an object with len == 0
func (*Is) OneOf ¶
func (is *Is) OneOf(a interface{}, b ...interface{})
OneOf performs a deep compare of the provided object and an array of comparison objects. It fails if the first object is not equal to one of the comparison objects.
OneOf does not respect type differences. If the types are different and comparable (eg int32 and int64), they will be compared as though they are the same type.
func (*Is) ShouldPanic ¶
func (is *Is) ShouldPanic(f func())
ShouldPanic expects the provided function to panic. If the function does not panic, this assertion fails.
func (*Is) Strict ¶ added in v1.1.1
Strict returns a copy of this instance of Is which aborts the test if a failure occurs. This is the default behavior, thus this method has no effect unless it is used to reverse a previous call to Lax.
func (*Is) WaitForTrue ¶
WaitForTrue waits until the provided func returns true. If the timeout is reached before the function returns true, the test will fail.
func (*Is) Zero ¶
func (is *Is) Zero(o interface{})
Zero checks the provided object to determine if it is the zero value for the type of that object. The zero value is the same as what the object would contain when initialized but not assigned.
This method, for example, would be used to determine if a string is empty, an array is empty or a map is empty. It could also be used to determine if a number is 0.
In cases such as slice, map, array and chan, a nil value is treated the same as an object with len == 0