Documentation ¶
Index ¶
- type Test
- func (t *Test) Attest(that bool, message string, formatters ...interface{})
- func (t *Test) AttestNoPanic(fun func(...interface{}), args ...interface{})
- func (t *Test) AttestNot(that bool, message string, formatters ...interface{})
- func (t *Test) AttestOrDo(that bool, callback func(*Test, ...interface{}), cbArgs ...interface{})
- func (t *Test) AttestPanics(fun func(...interface{}), args ...interface{})
- func (t *Test) Compares(var1, var2 interface{}, msgAndFmt ...interface{})
- func (t *Test) DoesNotCompare(var1, var2 interface{}, msgAndFmt ...interface{})
- func (t *Test) DoesNotMatch(pattern *regexp.Regexp, value string, msgAndFmt ...interface{})
- func (t *Test) EatError(value interface{}, err error) interface{}
- func (t *Test) Equals(var1, var2 interface{}, msgAndFormatters ...interface{})
- func (t *Test) FailOnError(value interface{}, err error, msgAndFormat ...interface{}) interface{}
- func (t *Test) GreaterThan(expected, variable interface{}, msgAndFmt ...interface{})
- func (t *Test) Handle(err error, msgAndFmt ...interface{})
- func (t *Test) HandleMultiple(e ...error)
- func (t *Test) ImmediateFailure()
- func (t *Test) LazyFailure()
- func (t *Test) LessThan(expected, variable interface{}, msgAndFmt ...interface{})
- func (t *Test) Matches(pattern *regexp.Regexp, value string, msgAndFmt ...interface{})
- func (t *Test) Negative(variable interface{}, msgAndFmt ...interface{})
- func (t *Test) NewRecorder(params ...string) (*httptest.ResponseRecorder, *http.Request)
- func (t *Test) Nil(variable interface{}, msgAndFmt ...interface{})
- func (t *Test) Not(that bool, message string, formatters ...interface{})
- func (t *Test) NotEqual(var1, var2 interface{}, msgAndFmt ...interface{})
- func (t *Test) NotNil(variable interface{}, msg string, formatters ...interface{})
- func (t *Test) NotSimilarTo(var1, var2 interface{}, msgAndFmt ...interface{})
- func (t *Test) Positive(variable interface{}, msgAndFmt ...interface{})
- func (t *Test) ResponseOK(response *http.Response, msgAndFmt ...interface{})
- func (t *Test) SimilarTo(var1, var2 interface{}, msgAndFmt ...interface{})
- func (t *Test) StopIf(err error, msgAndFmt ...interface{})
- func (t *Test) That(boolean bool, message string, formatters ...interface{})
- func (t *Test) TypeIs(typestring string, value interface{}, msgAndFmt ...interface{})
- func (t *Test) TypeIsNot(typestring string, value interface{}, msgAndFmt ...interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Test ¶
Test -- A structure for containing methods and data for asserting and testing assertion validity
func New ¶
New returns a new Test struct so that you don't get the linter complaining about unkeyed struct literals when the value has no key. This Test will fail lazily by default; that is, it will continue with the test if an assertion fails. This behavior can be toggled by calling .ImmediateFailure() on the returned Test.
func NewImmediate ¶ added in v1.3.1
NewImmediate returns a Test which will fail at the first error by default. This can be toggled by calling .LazyFailure() on the returned Test.
func (*Test) AttestNoPanic ¶
func (t *Test) AttestNoPanic(fun func(...interface{}), args ...interface{})
AttestNoPanic -- the inverse of AttestPanics
func (*Test) AttestOrDo ¶
AttestOrDo -- call `callback` with the Test as a parameter and fail the test should `that` be false.
func (*Test) AttestPanics ¶
func (t *Test) AttestPanics(fun func(...interface{}), args ...interface{})
AttestPanics -- Attest that when fun is called with args, it causes a panic. e.g.
t.AttestPanics(func(){log.Printf("Panics, passes test."); panic()}) t.AttestPanics(func(){log.Printf("Doesn't panic, fails test.")})
func (*Test) Compares ¶
func (t *Test) Compares(var1, var2 interface{}, msgAndFmt ...interface{})
Compares checks to see if var1 loosely equals var2. This allows for some minor type coersion before checking equality. For example, Test.Equals("5", 5) will fail, but Test.Compares("5", 5) will pass.
This works by converting all values to a string with fmt.Sprintf("%v", value) before checking equality.
func (*Test) DoesNotCompare ¶
func (t *Test) DoesNotCompare(var1, var2 interface{}, msgAndFmt ...interface{})
DoesNotCompare does the opposite of Compares/SimilarTo, the same as NotSimilarTo
func (*Test) DoesNotMatch ¶
DoesNotMatch inverts Matches
func (*Test) EatError ¶
EatError accepts two values, the latter of which is a nillable error. If the error is not nil, the test is failed. Regardless, the first value is returned through the function.
func (*Test) Equals ¶
func (t *Test) Equals( var1, var2 interface{}, msgAndFormatters ...interface{}, )
Equals checks that var1 is deeply equal to var2. Optionally, you can pass an additional string and additional string formatters to be passed to Test.Attest. If no message is specified, a message will be logged simply stating that the two values weren't equal.
func (*Test) FailOnError ¶
FailOnError accepts two values, the latter of which is a nillable error. If the error is not nil, the test is failed immediately.
func (*Test) GreaterThan ¶
func (t *Test) GreaterThan( expected, variable interface{}, msgAndFmt ...interface{}, )
GreaterThan -- log a message and fail if the variable is less than the expected value
func (*Test) HandleMultiple ¶
Handle -- log and fail for an arbitrary number of errors.
func (*Test) ImmediateFailure ¶ added in v1.3.1
func (t *Test) ImmediateFailure()
func (*Test) LazyFailure ¶ added in v1.3.1
func (t *Test) LazyFailure()
func (*Test) LessThan ¶
func (t *Test) LessThan(expected, variable interface{}, msgAndFmt ...interface{}, )
LessThan -- log a message and fail if variable is negative.
func (*Test) Negative ¶
func (t *Test) Negative(variable interface{}, msgAndFmt ...interface{})
Negative -- log a message and fail if variable is positive or zero.
func (*Test) NewRecorder ¶
NewRecorder retreives an httptest.ResponseRecorder and http.Request pointer pair. This function is variadic. That is, it accepts a varying number of arguments. If no arguments are passed, it uses the method "GET" and the default URL, with an empty body. This works for testing the index path. The first-priority parameter is the URL. It can begin with an actual URL, or a literal "/" and the default URL will be used with the given path. If two paramters are passed, they should be in the order (method, URL). An empty body will be used. If three paramters are passed, they are forwarded to the httptest.NewRequest function, with the following modifications:
- The default URL is prepended to a URL which starts with "/"
- The body is converted from a string with bytes.NewBufferString.
func (*Test) Nil ¶
func (t *Test) Nil(variable interface{}, msgAndFmt ...interface{})
Nil -- Log a message and fail if the variable is not nil
func (*Test) NotEqual ¶
func (t *Test) NotEqual(var1, var2 interface{}, msgAndFmt ...interface{})
NotEqual fails the test if var1 equals var2, with the given message and formatting.
func (*Test) NotNil ¶
NotNil -- Log a message and fail if the variable is nil. The explanatory message is not optional for this function. If the explanatory message were not provided, the default would be "nil was expected to not be nil" which isn't very descriptive.
func (*Test) NotSimilarTo ¶
func (t *Test) NotSimilarTo(var1, var2 interface{}, msgAndFmt ...interface{})
NotSimilarTo does the opposite of Compares/SimilarTo, the same as DoesNotCompare
func (*Test) Positive ¶
func (t *Test) Positive(variable interface{}, msgAndFmt ...interface{})
Positive -- log a message and fail if variable is negative or zero.
func (*Test) ResponseOK ¶
ResponseOK passes the test if the status code of the given response is less than 400
func (*Test) SimilarTo ¶
func (t *Test) SimilarTo(var1, var2 interface{}, msgAndFmt ...interface{})
SimilarTo is a semantic mirror of "Compares".
func (*Test) StopIf ¶
StopIf -- Fail the test and stop running it if an error is present, with optional message.