-- import "github.com/smartystreets/assertions"
Package assertions contains the implementations for all assertions which are
referenced in goconvey's convey package
(github.com/smartystreets/goconvey/convey) and gunit
(github.com/smartystreets/gunit) for use with the So(...) method. They can also
be used in traditional Go test functions and even in applications.
Many of the assertions lean heavily on work done by Aaron Jacobs in his excellent oglematchers library. (https://github.com/jacobsa/oglematchers) The ShouldResemble assertion leans heavily on work done by Daniel Jacques in his very helpful go-render library. (https://github.com/luci/go-render)
func GoConveyMode(yes bool)GoConveyMode provides control over JSON serialization of failures. When using the assertions in this package from the convey package JSON results are very helpful and can be rendered in a DIFF view. In that case, this function will be called with a true value to enable the JSON serialization. By default, the assertions in this package will not serializer a JSON result, making standalone ussage more convenient.
func ShouldAlmostEqual(actual interface{}, expected ...interface{}) stringShouldAlmostEqual makes sure that two parameters are close enough to being equal. The acceptable delta may be specified with a third argument, or a very small default delta will be used.
func ShouldBeBetween(actual interface{}, expected ...interface{}) stringShouldBeBetween receives exactly three parameters: an actual value, a lower bound, and an upper bound. It ensures that the actual value is between both bounds (but not equal to either of them).
func ShouldBeBetweenOrEqual(actual interface{}, expected ...interface{}) stringShouldBeBetweenOrEqual receives exactly three parameters: an actual value, a lower bound, and an upper bound. It ensures that the actual value is between both bounds or equal to one of them.
func ShouldBeBlank(actual interface{}, expected ...interface{}) stringShouldBeBlank receives exactly 1 string parameter and ensures that it is equal to "".
func ShouldBeChronological(actual interface{}, expected ...interface{}) stringShouldBeChronological receives a []time.Time slice and asserts that the are in chronological order starting with the first time.Time as the earliest.
func ShouldBeEmpty(actual interface{}, expected ...interface{}) stringShouldBeEmpty receives a single parameter (actual) and determines whether or not
calling len(actual) would return 0. It obeys the rules specified by the len
function for determining length: http://golang.org/pkg/builtin/#len
func ShouldBeFalse(actual interface{}, expected ...interface{}) stringShouldBeFalse receives a single parameter and ensures that it is false.
func ShouldBeGreaterThan(actual interface{}, expected ...interface{}) stringShouldBeGreaterThan receives exactly two parameters and ensures that the first is greater than the second.
func ShouldBeGreaterThanOrEqualTo(actual interface{}, expected ...interface{}) stringShouldBeGreaterThanOrEqualTo receives exactly two parameters and ensures that the first is greater than or equal to the second.
func ShouldBeIn(actual interface{}, expected ...interface{}) stringShouldBeIn receives at least 2 parameters. The first is a proposed member of the collection that is passed in either as the second parameter, or of the collection that is comprised of all the remaining parameters. This assertion ensures that the proposed member is in the collection (using ShouldEqual).
func ShouldBeLessThan(actual interface{}, expected ...interface{}) stringShouldBeLessThan receives exactly two parameters and ensures that the first is less than the second.
func ShouldBeLessThanOrEqualTo(actual interface{}, expected ...interface{}) stringShouldBeLessThan receives exactly two parameters and ensures that the first is less than or equal to the second.
func ShouldBeNil(actual interface{}, expected ...interface{}) stringShouldBeNil receives a single parameter and ensures that it is nil.
func ShouldBeTrue(actual interface{}, expected ...interface{}) stringShouldBeTrue receives a single parameter and ensures that it is true.
func ShouldBeZeroValue(actual interface{}, expected ...interface{}) stringShouldBeZeroValue receives a single parameter and ensures that it is the Go equivalent of the default value, or "zero" value.
func ShouldContain(actual interface{}, expected ...interface{}) stringShouldContain receives exactly two parameters. The first is a slice and the second is a proposed member. Membership is determined using ShouldEqual.
func ShouldContainKey(actual interface{}, expected ...interface{}) stringShouldContainKey receives exactly two parameters. The first is a map and the second is a proposed key. Keys are compared with a simple '=='.
func ShouldContainSubstring(actual interface{}, expected ...interface{}) stringShouldContainSubstring receives exactly 2 string parameters and ensures that the first contains the second as a substring.
func ShouldEndWith(actual interface{}, expected ...interface{}) stringShouldEndWith receives exactly 2 string parameters and ensures that the first ends with the second.
func ShouldEqual(actual interface{}, expected ...interface{}) stringShouldEqual receives exactly two parameters and does an equality check.
func ShouldEqualTrimSpace(actual interface{}, expected ...interface{}) stringShouldEqualTrimSpace receives exactly 2 string parameters and ensures that the first is equal to the second after removing all leading and trailing whitespace using strings.TrimSpace(first).
func ShouldEqualWithout(actual interface{}, expected ...interface{}) stringShouldEqualWithout receives exactly 3 string parameters and ensures that the first is equal to the second after removing all instances of the third from the first using strings.Replace(first, third, "", -1).
func ShouldHappenAfter(actual interface{}, expected ...interface{}) stringShouldHappenAfter receives exactly 2 time.Time arguments and asserts that the first happens after the second.
func ShouldHappenBefore(actual interface{}, expected ...interface{}) stringShouldHappenBefore receives exactly 2 time.Time arguments and asserts that the first happens before the second.
func ShouldHappenBetween(actual interface{}, expected ...interface{}) stringShouldHappenBetween receives exactly 3 time.Time arguments and asserts that the first happens between (not on) the second and third.
func ShouldHappenOnOrAfter(actual interface{}, expected ...interface{}) stringShouldHappenOnOrAfter receives exactly 2 time.Time arguments and asserts that the first happens on or after the second.
func ShouldHappenOnOrBefore(actual interface{}, expected ...interface{}) stringShouldHappenOnOrBefore receives exactly 2 time.Time arguments and asserts that the first happens on or before the second.
func ShouldHappenOnOrBetween(actual interface{}, expected ...interface{}) stringShouldHappenOnOrBetween receives exactly 3 time.Time arguments and asserts that the first happens between or on the second and third.
func ShouldHappenWithin(actual interface{}, expected ...interface{}) stringShouldHappenWithin receives a time.Time, a time.Duration, and a time.Time (3 arguments) and asserts that the first time.Time happens within or on the duration specified relative to the other time.Time.
func ShouldHaveLength(actual interface{}, expected ...interface{}) stringShouldHaveLength receives 2 parameters. The first is a collection to check the length of, the second being the expected length. It obeys the rules specified by the len function for determining length: http://golang.org/pkg/builtin/#len
func ShouldHaveSameTypeAs(actual interface{}, expected ...interface{}) stringShouldHaveSameTypeAs receives exactly two parameters and compares their underlying types for equality.
func ShouldImplement(actual interface{}, expectedList ...interface{}) stringShouldImplement receives exactly two parameters and ensures that the first implements the interface type of the second.
func ShouldNotAlmostEqual(actual interface{}, expected ...interface{}) stringShouldNotAlmostEqual is the inverse of ShouldAlmostEqual
func ShouldNotBeBetween(actual interface{}, expected ...interface{}) stringShouldNotBeBetween receives exactly three parameters: an actual value, a lower bound, and an upper bound. It ensures that the actual value is NOT between both bounds.
func ShouldNotBeBetweenOrEqual(actual interface{}, expected ...interface{}) stringShouldNotBeBetweenOrEqual receives exactly three parameters: an actual value, a lower bound, and an upper bound. It ensures that the actual value is nopt between the bounds nor equal to either of them.
func ShouldNotBeBlank(actual interface{}, expected ...interface{}) stringShouldNotBeBlank receives exactly 1 string parameter and ensures that it is equal to "".
func ShouldNotBeEmpty(actual interface{}, expected ...interface{}) stringShouldNotBeEmpty receives a single parameter (actual) and determines whether or
not calling len(actual) would return a value greater than zero. It obeys the
rules specified by the len function for determining length:
http://golang.org/pkg/builtin/#len
func ShouldNotBeIn(actual interface{}, expected ...interface{}) stringShouldNotBeIn receives at least 2 parameters. The first is a proposed member of the collection that is passed in either as the second parameter, or of the collection that is comprised of all the remaining parameters. This assertion ensures that the proposed member is NOT in the collection (using ShouldEqual).
func ShouldNotBeNil(actual interface{}, expected ...interface{}) stringShouldNotBeNil receives a single parameter and ensures that it is not nil.
func ShouldNotContain(actual interface{}, expected ...interface{}) stringShouldNotContain receives exactly two parameters. The first is a slice and the second is a proposed member. Membership is determinied using ShouldEqual.
func ShouldNotContainKey(actual interface{}, expected ...interface{}) stringShouldNotContainKey receives exactly two parameters. The first is a map and the second is a proposed absent key. Keys are compared with a simple '=='.
func ShouldNotContainSubstring(actual interface{}, expected ...interface{}) stringShouldNotContainSubstring receives exactly 2 string parameters and ensures that the first does NOT contain the second as a substring.
func ShouldNotEndWith(actual interface{}, expected ...interface{}) stringShouldEndWith receives exactly 2 string parameters and ensures that the first does not end with the second.
func ShouldNotEqual(actual interface{}, expected ...interface{}) stringShouldNotEqual receives exactly two parameters and does an inequality check.
func ShouldNotHappenOnOrBetween(actual interface{}, expected ...interface{}) stringShouldNotHappenOnOrBetween receives exactly 3 time.Time arguments and asserts that the first does NOT happen between or on the second or third.
func ShouldNotHappenWithin(actual interface{}, expected ...interface{}) stringShouldNotHappenWithin receives a time.Time, a time.Duration, and a time.Time (3 arguments) and asserts that the first time.Time does NOT happen within or on the duration specified relative to the other time.Time.
func ShouldNotHaveSameTypeAs(actual interface{}, expected ...interface{}) stringShouldNotHaveSameTypeAs receives exactly two parameters and compares their underlying types for inequality.
func ShouldNotImplement(actual interface{}, expectedList ...interface{}) stringShouldNotImplement receives exactly two parameters and ensures that the first does NOT implement the interface type of the second.
func ShouldNotPanic(actual interface{}, expected ...interface{}) (message string)ShouldNotPanic receives a void, niladic function and expects to execute the function without any panic.
func ShouldNotPanicWith(actual interface{}, expected ...interface{}) (message string)ShouldNotPanicWith receives a void, niladic function and expects to recover a panic whose content differs from the second argument.
func ShouldNotPointTo(actual interface{}, expected ...interface{}) stringShouldNotPointTo receives exactly two parameters and checks to see that they point to different addresess.
func ShouldNotResemble(actual interface{}, expected ...interface{}) stringShouldNotResemble receives exactly two parameters and does an inverse deep equal check (see reflect.DeepEqual)
func ShouldNotStartWith(actual interface{}, expected ...interface{}) stringShouldNotStartWith receives exactly 2 string parameters and ensures that the first does not start with the second.
func ShouldPanic(actual interface{}, expected ...interface{}) (message string)ShouldPanic receives a void, niladic function and expects to recover a panic.
func ShouldPanicWith(actual interface{}, expected ...interface{}) (message string)ShouldPanicWith receives a void, niladic function and expects to recover a panic with the second argument as the content.
func ShouldPointTo(actual interface{}, expected ...interface{}) stringShouldPointTo receives exactly two parameters and checks to see that they point to the same address.
func ShouldResemble(actual interface{}, expected ...interface{}) stringShouldResemble receives exactly two parameters and does a deep equal check (see reflect.DeepEqual)
func ShouldStartWith(actual interface{}, expected ...interface{}) stringShouldStartWith receives exactly 2 string parameters and ensures that the first starts with the second.
func So(actual interface{}, assert assertion, expected ...interface{}) (bool, string)So is a convenience function (as opposed to an inconvenience function?) for
running assertions on arbitrary arguments in any context, be it for testing or
even application logging. It allows you to perform assertion-like behavior (and
get nicely formatted messages detailing discrepancies) but without the program
blowing up or panicking. All that is required is to import this package and call
So with one of the assertions exported by this package as the second
parameter. The first return parameter is a boolean indicating if the assertion
was true. The second return parameter is the well-formatted message showing why
an assertion was incorrect, or blank if the assertion was correct.
Example:
if ok, message := So(x, ShouldBeGreaterThan, y); !ok {
log.Println(message)
}
type Assertion struct {
}func New(t testingT) *AssertionNew swallows the *testing.T struct and prints failed assertions using t.Error. Example: assertions.New(t).So(1, should.Equal, 1)
func (this *Assertion) Failed() boolFailed reports whether any calls to So (on this Assertion instance) have failed.
func (this *Assertion) So(actual interface{}, assert assertion, expected ...interface{}) boolSo calls the standalone So function and additionally, calls t.Error in failure scenarios.
type FailureView struct {
Message string `json:"Message"`
Expected string `json:"Expected"`
Actual string `json:"Actual"`
}This struct is also declared in github.com/smartystreets/goconvey/convey/reporting. The json struct tags should be equal in both declarations.
type Serializer interface {
// contains filtered or unexported methods
}