GoConvey comes with a lot of standard assertions you can use with So().

General Equality

  1. So(thing1, ShouldEqual, thing2)
  2. So(thing1, ShouldNotEqual, thing2)
  3. So(thing1, ShouldResemble, thing2) // a deep equals for arrays, slices, maps, and structs
  4. So(thing1, ShouldNotResemble, thing2)
  5. So(thing1, ShouldPointTo, thing2)
  6. So(thing1, ShouldNotPointTo, thing2)
  7. So(thing1, ShouldBeNil)
  8. So(thing1, ShouldNotBeNil)
  9. So(thing1, ShouldBeTrue)
  10. So(thing1, ShouldBeFalse)
  11. So(thing1, ShouldBeZeroValue)

Numeric Quantity comparison

  1. So(1, ShouldBeGreaterThan, 0)
  2. So(1, ShouldBeGreaterThanOrEqualTo, 0)
  3. So(1, ShouldBeLessThan, 2)
  4. So(1, ShouldBeLessThanOrEqualTo, 2)
  5. So(1.1, ShouldBeBetween, .8, 1.2)
  6. So(1.1, ShouldNotBeBetween, 2, 3)
  7. So(1.1, ShouldBeBetweenOrEqual, .9, 1.1)
  8. So(1.1, ShouldNotBeBetweenOrEqual, 1000, 2000)
  9. So(1.0, ShouldAlmostEqual, 0.99999999, .0001) // tolerance is optional; default 0.0000000001
  10. So(1.0, ShouldNotAlmostEqual, 0.9, .0001)

Collections

  1. So([]int{2, 4, 6}, ShouldContain, 4)
  2. So([]int{2, 4, 6}, ShouldNotContain, 5)
  3. So(4, ShouldBeIn, ...[]int{2, 4, 6})
  4. So(4, ShouldNotBeIn, ...[]int{1, 3, 5})
  5. So([]int{}, ShouldBeEmpty)
  6. So([]int{1}, ShouldNotBeEmpty)
  7. So(map[string]string{"a": "b"}, ShouldContainKey, "a")
  8. So(map[string]string{"a": "b"}, ShouldNotContainKey, "b")
  9. So(map[string]string{"a": "b"}, ShouldNotBeEmpty)
  10. So(map[string]string{}, ShouldBeEmpty)
  11. So(map[string]string{"a": "b"}, ShouldHaveLength, 1) // supports map, slice, chan, and string

Strings

  1. So("asdf", ShouldStartWith, "as")
  2. So("asdf", ShouldNotStartWith, "df")
  3. So("asdf", ShouldEndWith, "df")
  4. So("asdf", ShouldNotEndWith, "df")
  5. So("asdf", ShouldContainSubstring, "sd") // optional 'expected occurences' arguments?
  6. So("asdf", ShouldNotContainSubstring, "er")
  7. So("adsf", ShouldBeBlank)
  8. So("asdf", ShouldNotBeBlank)

panic

  1. So(func(), ShouldPanic)
  2. So(func(), ShouldNotPanic)
  3. So(func(), ShouldPanicWith, "") // or errors.New("something")
  4. So(func(), ShouldNotPanicWith, "") // or errors.New("something")

Type checking

  1. So(1, ShouldHaveSameTypeAs, 0)
  2. So(1, ShouldNotHaveSameTypeAs, "asdf")

time.Time (and time.Duration)

  1. So(time.Now(), ShouldHappenBefore, time.Now())
  2. So(time.Now(), ShouldHappenOnOrBefore, time.Now())
  3. So(time.Now(), ShouldHappenAfter, time.Now())
  4. So(time.Now(), ShouldHappenOnOrAfter, time.Now())
  5. So(time.Now(), ShouldHappenBetween, time.Now(), time.Now())
  6. So(time.Now(), ShouldHappenOnOrBetween, time.Now(), time.Now())
  7. So(time.Now(), ShouldNotHappenOnOrBetween, time.Now(), time.Now())
  8. So(time.Now(), ShouldHappenWithin, duration, time.Now())
  9. So(time.Now(), ShouldNotHappenWithin, duration, time.Now())

Thanks to github.com/jacobsa for his excellent oglematchers library, which is what many of these methods make use of to do their jobs.

[[Next|Custom-Assertions]]

Next up, learn about [[building your own assertions|Custom-Assertions]].