Documentation ¶
Overview ¶
Package assert adds helpers to make writing tests easier.
Index ¶
- Constants
- func CheckFilter(t *testing.T, filter Filter)
- func Count() int
- func Elapsed() time.Duration
- func Increment()
- func Main(m *testing.M)
- func Rate() float64
- func ReportRate()
- func Started()
- type Any
- type Assertions
- func (a *Assertions) All(target interface{}, predicate Predicate, userMessageComponents ...interface{})
- func (a *Assertions) AllOfFloat64(target []float64, predicate PredicateOfFloat, ...)
- func (a *Assertions) AllOfInt(target []int, predicate PredicateOfInt, userMessageComponents ...interface{})
- func (a *Assertions) AllOfString(target []string, predicate PredicateOfString, ...)
- func (a *Assertions) Any(target interface{}, predicate Predicate, userMessageComponents ...interface{})
- func (a *Assertions) AnyOfFloat64(target []float64, predicate PredicateOfFloat, ...)
- func (a *Assertions) AnyOfInt(target []int, predicate PredicateOfInt, userMessageComponents ...interface{})
- func (a *Assertions) AnyOfString(target []string, predicate PredicateOfString, ...)
- func (a *Assertions) Contains(corpus, substring string, userMessageComponents ...interface{})
- func (a *Assertions) Empty(collection interface{}, userMessageComponents ...interface{})
- func (a *Assertions) EndTimeout()
- func (a *Assertions) Equal(expected interface{}, actual interface{}, userMessageComponents ...interface{})
- func (a *Assertions) FailNow(userMessageComponents ...interface{})
- func (a *Assertions) False(object bool, userMessageComponents ...interface{})
- func (a *Assertions) FileExists(filepath string, userMessageComponents ...interface{})
- func (a *Assertions) InDelta(f0, f1, delta float64, userMessageComponents ...interface{})
- func (a *Assertions) InTimeDelta(t1, t2 time.Time, delta time.Duration, userMessageComponents ...interface{})
- func (a *Assertions) Len(collection interface{}, length int, userMessageComponents ...interface{})
- func (a *Assertions) Nil(object interface{}, userMessageComponents ...interface{})
- func (a *Assertions) NonFatal() *Optional
- func (a *Assertions) None(target interface{}, predicate Predicate, userMessageComponents ...interface{})
- func (a *Assertions) NoneOfFloat64(target []float64, predicate PredicateOfFloat, ...)
- func (a *Assertions) NoneOfInt(target []int, predicate PredicateOfInt, userMessageComponents ...interface{})
- func (a *Assertions) NoneOfString(target []string, predicate PredicateOfString, ...)
- func (a *Assertions) NotContains(corpus, substring string, userMessageComponents ...interface{})
- func (a *Assertions) NotEmpty(collection interface{}, userMessageComponents ...interface{})
- func (a *Assertions) NotEqual(expected interface{}, actual interface{}, userMessageComponents ...interface{})
- func (a *Assertions) NotNil(object interface{}, userMessageComponents ...interface{})
- func (a *Assertions) NotZero(value interface{}, userMessageComponents ...interface{})
- func (a *Assertions) Output() io.Writer
- func (a *Assertions) PanicEqual(expected interface{}, action func(), userMessageComponents ...interface{})
- func (a *Assertions) ReferenceEqual(expected interface{}, actual interface{}, userMessageComponents ...interface{})
- func (a *Assertions) StartTimeout(timeout time.Duration, userMessageComponents ...interface{})
- func (a *Assertions) True(object bool, userMessageComponents ...interface{})
- func (a *Assertions) WithFilter(filter Filter) *Assertions
- func (a *Assertions) WithOutput(w io.Writer) *Assertions
- func (a *Assertions) Zero(value interface{}, userMessageComponents ...interface{})
- type Filter
- type Optional
- func (o *Optional) All(target interface{}, predicate Predicate, userMessageComponents ...interface{}) bool
- func (o *Optional) AllOfFloat(target []float64, predicate PredicateOfFloat, ...) bool
- func (o *Optional) AllOfInt(target []int, predicate PredicateOfInt, userMessageComponents ...interface{}) bool
- func (o *Optional) AllOfString(target []string, predicate PredicateOfString, ...) bool
- func (o *Optional) Any(target interface{}, predicate Predicate, userMessageComponents ...interface{}) bool
- func (o *Optional) AnyOfFloat(target []float64, predicate PredicateOfFloat, ...) bool
- func (o *Optional) AnyOfInt(target []int, predicate PredicateOfInt, userMessageComponents ...interface{}) bool
- func (o *Optional) AnyOfString(target []string, predicate PredicateOfString, ...) bool
- func (o *Optional) Contains(corpus, substring string, userMessageComponents ...interface{}) bool
- func (o *Optional) Empty(collection interface{}, userMessageComponents ...interface{}) bool
- func (o *Optional) Equal(expected interface{}, actual interface{}, userMessageComponents ...interface{}) bool
- func (o *Optional) Fail(userMessageComponents ...interface{})
- func (o *Optional) False(object bool, userMessageComponents ...interface{}) bool
- func (o *Optional) FileExists(filepath string, userMessageComponents ...interface{}) bool
- func (o *Optional) InDelta(a, b, delta float64, userMessageComponents ...interface{}) bool
- func (o *Optional) InTimeDelta(a, b time.Time, delta time.Duration, userMessageComponents ...interface{}) bool
- func (o *Optional) Len(collection interface{}, length int, userMessageComponents ...interface{}) bool
- func (o *Optional) Nil(object interface{}, userMessageComponents ...interface{}) bool
- func (o *Optional) None(target interface{}, predicate Predicate, userMessageComponents ...interface{}) bool
- func (o *Optional) NoneOfFloat(target []float64, predicate PredicateOfFloat, ...) bool
- func (o *Optional) NoneOfInt(target []int, predicate PredicateOfInt, userMessageComponents ...interface{}) bool
- func (o *Optional) NoneOfString(target []string, predicate PredicateOfString, ...) bool
- func (o *Optional) NotContains(corpus, substring string, userMessageComponents ...interface{}) bool
- func (o *Optional) NotEmpty(collection interface{}, userMessageComponents ...interface{}) bool
- func (o *Optional) NotEqual(expected interface{}, actual interface{}, userMessageComponents ...interface{}) bool
- func (o *Optional) NotNil(object interface{}, userMessageComponents ...interface{}) bool
- func (o *Optional) NotZero(value interface{}, userMessageComponents ...interface{}) bool
- func (o *Optional) Output() io.Writer
- func (o *Optional) PanicEqual(expected interface{}, action func(), userMessageComponents ...interface{}) bool
- func (o *Optional) ReferenceEqual(expected interface{}, actual interface{}, userMessageComponents ...interface{}) bool
- func (o *Optional) True(object bool, userMessageComponents ...interface{}) bool
- func (o *Optional) WithOutput(w io.Writer) *Optional
- func (o *Optional) Zero(value interface{}, userMessageComponents ...interface{}) bool
- type Predicate
- type PredicateOfFloat
- type PredicateOfInt
- type PredicateOfString
- type PredicateOfTime
Constants ¶
const ( // RED is the ansi escape code fragment for red. RED = "31" // BLUE is the ansi escape code fragment for blue. BLUE = "94" // GREEN is the ansi escape code fragment for green. GREEN = "32" // YELLOW is the ansi escape code fragment for yellow. YELLOW = "33" // WHITE is the ansi escape code fragment for white. WHITE = "37" // GRAY is the ansi escape code fragment for gray. GRAY = "90" // EMPTY is a constant for the empty (0 length) string. EMPTY = "" )
const ( // Unit is a filter for unit tests. Unit = "unit" // Acceptance is a filter for acceptance tests. Acceptance = "acceptance" // Integration is a filter for integration tests. Integration = "integration" )
Filters
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Assertions ¶
type Assertions struct {
// contains filtered or unexported fields
}
Assertions is the main entry point for using the assertions library.
func Empty ¶
func Empty() *Assertions
Empty returns an empty assertions class; useful when you want to apply assertions w/o hooking into the testing framework.
func Filtered ¶
func Filtered(t *testing.T, filter Filter) *Assertions
Filtered returns a new instance of `Assertions`.
func (*Assertions) All ¶
func (a *Assertions) All(target interface{}, predicate Predicate, userMessageComponents ...interface{})
All applies a predicate.
func (*Assertions) AllOfFloat64 ¶
func (a *Assertions) AllOfFloat64(target []float64, predicate PredicateOfFloat, userMessageComponents ...interface{})
AllOfFloat64 applies a predicate.
func (*Assertions) AllOfInt ¶
func (a *Assertions) AllOfInt(target []int, predicate PredicateOfInt, userMessageComponents ...interface{})
AllOfInt applies a predicate.
func (*Assertions) AllOfString ¶
func (a *Assertions) AllOfString(target []string, predicate PredicateOfString, userMessageComponents ...interface{})
AllOfString applies a predicate.
func (*Assertions) Any ¶
func (a *Assertions) Any(target interface{}, predicate Predicate, userMessageComponents ...interface{})
Any applies a predicate.
func (*Assertions) AnyOfFloat64 ¶
func (a *Assertions) AnyOfFloat64(target []float64, predicate PredicateOfFloat, userMessageComponents ...interface{})
AnyOfFloat64 applies a predicate.
func (*Assertions) AnyOfInt ¶
func (a *Assertions) AnyOfInt(target []int, predicate PredicateOfInt, userMessageComponents ...interface{})
AnyOfInt applies a predicate.
func (*Assertions) AnyOfString ¶
func (a *Assertions) AnyOfString(target []string, predicate PredicateOfString, userMessageComponents ...interface{})
AnyOfString applies a predicate.
func (*Assertions) Contains ¶
func (a *Assertions) Contains(corpus, substring string, userMessageComponents ...interface{})
Contains asserts that a substring is present in a corpus.
func (*Assertions) Empty ¶
func (a *Assertions) Empty(collection interface{}, userMessageComponents ...interface{})
Empty asserts that a collection is empty.
func (*Assertions) EndTimeout ¶
func (a *Assertions) EndTimeout()
EndTimeout marks a timed block as complete.
func (*Assertions) Equal ¶
func (a *Assertions) Equal(expected interface{}, actual interface{}, userMessageComponents ...interface{})
Equal asserts that two objects are deeply equal.
func (*Assertions) FailNow ¶
func (a *Assertions) FailNow(userMessageComponents ...interface{})
FailNow forces a test failure (useful for debugging).
func (*Assertions) False ¶
func (a *Assertions) False(object bool, userMessageComponents ...interface{})
False asserts a boolean is false.
func (*Assertions) FileExists ¶
func (a *Assertions) FileExists(filepath string, userMessageComponents ...interface{})
FileExists asserts that a file exists at a given filepath on disk.
func (*Assertions) InDelta ¶
func (a *Assertions) InDelta(f0, f1, delta float64, userMessageComponents ...interface{})
InDelta asserts that two floats are within a delta.
The delta is computed by the absolute of the difference betwee `f0` and `f1` and testing if that absolute difference is strictly less than `delta` if greater, it will fail the assertion, if delta is equal to or greater than difference the assertion will pass.
func (*Assertions) InTimeDelta ¶
func (a *Assertions) InTimeDelta(t1, t2 time.Time, delta time.Duration, userMessageComponents ...interface{})
InTimeDelta asserts that times t1 and t2 are within a delta.
func (*Assertions) Len ¶
func (a *Assertions) Len(collection interface{}, length int, userMessageComponents ...interface{})
Len asserts that a collection has a given length.
func (*Assertions) Nil ¶
func (a *Assertions) Nil(object interface{}, userMessageComponents ...interface{})
Nil asserts that a reference is nil.
func (*Assertions) NonFatal ¶
func (a *Assertions) NonFatal() *Optional
NonFatal transitions the assertion into a `NonFatal` assertion; that is, one that will not cause the test to abort if it fails. NonFatal assertions are useful when you want to check many properties during a test, but only on an informational basis. They will typically return a bool to indicate if the assertion succeeded, or if you should consider the overall test to still be a success.
func (*Assertions) None ¶
func (a *Assertions) None(target interface{}, predicate Predicate, userMessageComponents ...interface{})
None applies a predicate.
func (*Assertions) NoneOfFloat64 ¶
func (a *Assertions) NoneOfFloat64(target []float64, predicate PredicateOfFloat, userMessageComponents ...interface{})
NoneOfFloat64 applies a predicate.
func (*Assertions) NoneOfInt ¶
func (a *Assertions) NoneOfInt(target []int, predicate PredicateOfInt, userMessageComponents ...interface{})
NoneOfInt applies a predicate.
func (*Assertions) NoneOfString ¶
func (a *Assertions) NoneOfString(target []string, predicate PredicateOfString, userMessageComponents ...interface{})
NoneOfString applies a predicate.
func (*Assertions) NotContains ¶
func (a *Assertions) NotContains(corpus, substring string, userMessageComponents ...interface{})
NotContains asserts that a substring is present in a corpus.
func (*Assertions) NotEmpty ¶
func (a *Assertions) NotEmpty(collection interface{}, userMessageComponents ...interface{})
NotEmpty asserts that a collection is not empty.
func (*Assertions) NotEqual ¶
func (a *Assertions) NotEqual(expected interface{}, actual interface{}, userMessageComponents ...interface{})
NotEqual asserts that two objects are not deeply equal.
func (*Assertions) NotNil ¶
func (a *Assertions) NotNil(object interface{}, userMessageComponents ...interface{})
NotNil asserts that a reference is not nil.
func (*Assertions) NotZero ¶
func (a *Assertions) NotZero(value interface{}, userMessageComponents ...interface{})
NotZero asserts that a value is not equal to it's default value.
func (*Assertions) Output ¶
func (a *Assertions) Output() io.Writer
Output returns the underlying output writer.
func (*Assertions) PanicEqual ¶
func (a *Assertions) PanicEqual(expected interface{}, action func(), userMessageComponents ...interface{})
PanicEqual asserts the panic emitted by an actin equals an expected value.
func (*Assertions) ReferenceEqual ¶
func (a *Assertions) ReferenceEqual(expected interface{}, actual interface{}, userMessageComponents ...interface{})
ReferenceEqual asserts that two objects are the same reference in memory.
func (*Assertions) StartTimeout ¶
func (a *Assertions) StartTimeout(timeout time.Duration, userMessageComponents ...interface{})
StartTimeout starts a timed block.
func (*Assertions) True ¶
func (a *Assertions) True(object bool, userMessageComponents ...interface{})
True asserts a boolean is true.
func (*Assertions) WithFilter ¶
func (a *Assertions) WithFilter(filter Filter) *Assertions
WithFilter sets the filter.
func (*Assertions) WithOutput ¶
func (a *Assertions) WithOutput(w io.Writer) *Assertions
WithOutput sets the assertions output. Error messages will be written to this in addition to the test handler.
func (*Assertions) Zero ¶
func (a *Assertions) Zero(value interface{}, userMessageComponents ...interface{})
Zero asserts that a value is equal to it's default value.
type Optional ¶
type Optional struct {
// contains filtered or unexported fields
}
Optional is an assertion type that does not stop a test if an assertion fails, simply outputs the error.
func (*Optional) All ¶
func (o *Optional) All(target interface{}, predicate Predicate, userMessageComponents ...interface{}) bool
All applies a predicate.
func (*Optional) AllOfFloat ¶
func (o *Optional) AllOfFloat(target []float64, predicate PredicateOfFloat, userMessageComponents ...interface{}) bool
AllOfFloat applies a predicate.
func (*Optional) AllOfInt ¶
func (o *Optional) AllOfInt(target []int, predicate PredicateOfInt, userMessageComponents ...interface{}) bool
AllOfInt applies a predicate.
func (*Optional) AllOfString ¶
func (o *Optional) AllOfString(target []string, predicate PredicateOfString, userMessageComponents ...interface{}) bool
AllOfString applies a predicate.
func (*Optional) Any ¶
func (o *Optional) Any(target interface{}, predicate Predicate, userMessageComponents ...interface{}) bool
Any applies a predicate.
func (*Optional) AnyOfFloat ¶
func (o *Optional) AnyOfFloat(target []float64, predicate PredicateOfFloat, userMessageComponents ...interface{}) bool
AnyOfFloat applies a predicate.
func (*Optional) AnyOfInt ¶
func (o *Optional) AnyOfInt(target []int, predicate PredicateOfInt, userMessageComponents ...interface{}) bool
AnyOfInt applies a predicate.
func (*Optional) AnyOfString ¶
func (o *Optional) AnyOfString(target []string, predicate PredicateOfString, userMessageComponents ...interface{}) bool
AnyOfString applies a predicate.
func (*Optional) Equal ¶
func (o *Optional) Equal(expected interface{}, actual interface{}, userMessageComponents ...interface{}) bool
Equal asserts that two objects are equal.
func (*Optional) Fail ¶
func (o *Optional) Fail(userMessageComponents ...interface{})
Fail manually injects a failure.
func (*Optional) FileExists ¶
FileExists asserts that a file exists on disk at a given filepath.
func (*Optional) InTimeDelta ¶
func (o *Optional) InTimeDelta(a, b time.Time, delta time.Duration, userMessageComponents ...interface{}) bool
InTimeDelta returns if two times are separated by a given delta.
func (*Optional) Len ¶
func (o *Optional) Len(collection interface{}, length int, userMessageComponents ...interface{}) bool
Len asserts that the collection has a specified length.
func (*Optional) None ¶
func (o *Optional) None(target interface{}, predicate Predicate, userMessageComponents ...interface{}) bool
None applies a predicate.
func (*Optional) NoneOfFloat ¶
func (o *Optional) NoneOfFloat(target []float64, predicate PredicateOfFloat, userMessageComponents ...interface{}) bool
NoneOfFloat applies a predicate.
func (*Optional) NoneOfInt ¶
func (o *Optional) NoneOfInt(target []int, predicate PredicateOfInt, userMessageComponents ...interface{}) bool
NoneOfInt applies a predicate.
func (*Optional) NoneOfString ¶
func (o *Optional) NoneOfString(target []string, predicate PredicateOfString, userMessageComponents ...interface{}) bool
NoneOfString applies a predicate.
func (*Optional) NotContains ¶
NotContains checks if a substring is not present in a corpus.
func (*Optional) NotEqual ¶
func (o *Optional) NotEqual(expected interface{}, actual interface{}, userMessageComponents ...interface{}) bool
NotEqual asserts that two objects are not equal.
func (*Optional) PanicEqual ¶
func (o *Optional) PanicEqual(expected interface{}, action func(), userMessageComponents ...interface{}) bool
PanicEqual asserts the panic emitted by an actin equals an expected value.
func (*Optional) ReferenceEqual ¶
func (o *Optional) ReferenceEqual(expected interface{}, actual interface{}, userMessageComponents ...interface{}) bool
ReferenceEqual asserts that two objects are the same underlying reference in memory.
func (*Optional) WithOutput ¶
WithOutput sets an output to capture error output.
type PredicateOfFloat ¶
PredicateOfFloat is a func that takes a float64 and returns a bool.
type PredicateOfInt ¶
PredicateOfInt is a func that takes an int and returns a bool.
type PredicateOfString ¶
PredicateOfString is a func that takes a string and returns a bool.
type PredicateOfTime ¶
PredicateOfTime is a func that takes a time.Time and returns a bool.