assertions

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package assertions contains the implementations for all assertions used with the So(...) method.

A few of the assertions lean heavily on work done by Aaron Jacobs in his excellent oglematchers library. (https://github.com/jacobsa/oglematchers) The ShouldEqual assertion leans heavily on work done by Daniel Jacques in his very helpful go-render library. (https://github.com/luci/go-render)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShouldAlmostEqual

func ShouldAlmostEqual(actual any, expected ...any) string

ShouldAlmostEqual 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

func ShouldBeBetween(actual any, expected ...any) string

ShouldBeBetween 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

func ShouldBeBetweenOrEqual(actual any, expected ...any) string

ShouldBeBetweenOrEqual 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

func ShouldBeBlank(actual any, expected ...any) string

ShouldBeBlank receives exactly 1 string parameter and ensures that it is equal to "".

func ShouldBeChronological

func ShouldBeChronological(actual any, expected ...any) string

ShouldBeChronological receives a []time.Time slice and asserts that they are in chronological order starting with the first time.Time as the earliest.

func ShouldBeEmpty

func ShouldBeEmpty(actual any, expected ...any) string

ShouldBeEmpty receives a single parameter (actual) and determines whether 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

func ShouldBeFalse(actual any, expected ...any) string

ShouldBeFalse receives a single parameter and ensures that it is false.

func ShouldBeGreaterThan

func ShouldBeGreaterThan(actual any, expected ...any) string

ShouldBeGreaterThan receives exactly two parameters and ensures that the first is greater than the second.

func ShouldBeGreaterThanOrEqualTo

func ShouldBeGreaterThanOrEqualTo(actual any, expected ...any) string

ShouldBeGreaterThanOrEqualTo receives exactly two parameters and ensures that the first is greater than or equal to the second.

func ShouldBeIn

func ShouldBeIn(actual any, expected ...any) string

ShouldBeIn 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 consists of all the remaining parameters. This assertion ensures that the proposed member is in the collection (using ShouldEqual).

func ShouldBeLessThan

func ShouldBeLessThan(actual any, expected ...any) string

ShouldBeLessThan receives exactly two parameters and ensures that the first is less than the second.

func ShouldBeLessThanOrEqualTo

func ShouldBeLessThanOrEqualTo(actual any, expected ...any) string

ShouldBeLessThanOrEqualTo receives exactly two parameters and ensures that the first is less than or equal to the second.

func ShouldBeNil

func ShouldBeNil(actual any, expected ...any) string

ShouldBeNil receives a single parameter and ensures that it is nil.

func ShouldBeTrue

func ShouldBeTrue(actual any, expected ...any) string

ShouldBeTrue receives a single parameter and ensures that it is true.

func ShouldBeZeroValue

func ShouldBeZeroValue(actual any, expected ...any) string

ShouldBeZeroValue receives a single parameter and ensures that it is the Go equivalent of the default value, or "zero" value.

func ShouldContain

func ShouldContain(actual any, expected ...any) string

ShouldContain receives exactly two parameters. The first is a slice and the second is a proposed member. Membership is determined using ShouldEqual.

func ShouldContainKey

func ShouldContainKey(actual any, expected ...any) string

ShouldContainKey receives exactly two parameters. The first is a map and the second is a proposed key. Keys are compared with a simple '=='.

func ShouldContainSubstring

func ShouldContainSubstring(actual any, expected ...any) string

ShouldContainSubstring receives exactly 2 string parameters and ensures that the first contains the second as a substring.

func ShouldEndWith

func ShouldEndWith(actual any, expected ...any) string

ShouldEndWith receives exactly 2 string parameters and ensures that the first ends with the second.

func ShouldEqual

func ShouldEqual(actual any, expected ...any) string

ShouldEqual receives exactly two parameters and does an equality check using the following semantics: It uses reflect.DeepEqual in most cases, but also compares numerics regardless of specific type and compares time.Time values using the time.Equal method.

func ShouldHappenAfter

func ShouldHappenAfter(actual any, expected ...any) string

ShouldHappenAfter receives exactly 2 time.Time arguments and asserts that the first happens after the second.

func ShouldHappenBefore

func ShouldHappenBefore(actual any, expected ...any) string

ShouldHappenBefore receives exactly 2 time.Time arguments and asserts that the first happens before the second.

func ShouldHappenBetween

func ShouldHappenBetween(actual any, expected ...any) string

ShouldHappenBetween receives exactly 3 time.Time arguments and asserts that the first happens between (not on) the second and third.

func ShouldHappenOnOrAfter

func ShouldHappenOnOrAfter(actual any, expected ...any) string

ShouldHappenOnOrAfter receives exactly 2 time.Time arguments and asserts that the first happens on or after the second.

func ShouldHappenOnOrBefore

func ShouldHappenOnOrBefore(actual any, expected ...any) string

ShouldHappenOnOrBefore receives exactly 2 time.Time arguments and asserts that the first happens on or before the second.

func ShouldHappenOnOrBetween

func ShouldHappenOnOrBetween(actual any, expected ...any) string

ShouldHappenOnOrBetween receives exactly 3 time.Time arguments and asserts that the first happens between or on the second and third.

func ShouldHappenWithin

func ShouldHappenWithin(actual any, expected ...any) string

ShouldHappenWithin 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

func ShouldHaveLength(actual any, expected ...any) string

ShouldHaveLength 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

func ShouldHaveSameTypeAs(actual any, expected ...any) string

ShouldHaveSameTypeAs receives exactly two parameters and compares their underlying types for equality.

func ShouldNotAlmostEqual

func ShouldNotAlmostEqual(actual any, expected ...any) string

ShouldNotAlmostEqual is the inverse of ShouldAlmostEqual

func ShouldNotBeBetween

func ShouldNotBeBetween(actual any, expected ...any) string

ShouldNotBeBetween 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

func ShouldNotBeBetweenOrEqual(actual any, expected ...any) string

ShouldNotBeBetweenOrEqual 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

func ShouldNotBeBlank(actual any, expected ...any) string

ShouldNotBeBlank receives exactly 1 string parameter and ensures that it is not equal to "".

func ShouldNotBeChronological

func ShouldNotBeChronological(actual any, expected ...any) string

ShouldNotBeChronological receives a []time.Time slice and asserts that they are NOT in chronological order.

func ShouldNotBeEmpty

func ShouldNotBeEmpty(actual any, expected ...any) string

ShouldNotBeEmpty receives a single parameter (actual) and determines whether 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

func ShouldNotBeIn(actual any, expected ...any) string

ShouldNotBeIn 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 consists of all the remaining parameters. This assertion ensures that the proposed member is NOT in the collection (using ShouldEqual).

func ShouldNotBeNil

func ShouldNotBeNil(actual any, expected ...any) string

ShouldNotBeNil receives a single parameter and ensures that it is not nil.

func ShouldNotBeZeroValue

func ShouldNotBeZeroValue(actual any, expected ...any) string

ShouldNotBeZeroValue receives a single parameter and ensures that it is NOT the Go equivalent of the default value, or "zero" value.

func ShouldNotContain

func ShouldNotContain(actual any, expected ...any) string

ShouldNotContain receives exactly two parameters. The first is a slice and the second is a proposed member. Membership is determined using ShouldEqual.

func ShouldNotContainKey

func ShouldNotContainKey(actual any, expected ...any) string

ShouldNotContainKey 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

func ShouldNotContainSubstring(actual any, expected ...any) string

ShouldNotContainSubstring receives exactly 2 string parameters and ensures that the first does NOT contain the second as a substring.

func ShouldNotEndWith

func ShouldNotEndWith(actual any, expected ...any) string

ShouldNotEndWith receives exactly 2 string parameters and ensures that the first does not end with the second.

func ShouldNotEqual

func ShouldNotEqual(actual any, expected ...any) string

ShouldNotEqual receives exactly two parameters and does an inequality check. See ShouldEqual for details on how equality is determined.

func ShouldNotHappenOnOrBetween

func ShouldNotHappenOnOrBetween(actual any, expected ...any) string

ShouldNotHappenOnOrBetween receives exactly 3 time.Time arguments and asserts that the first does NOT happen between or on the second or third.

func ShouldNotHappenWithin

func ShouldNotHappenWithin(actual any, expected ...any) string

ShouldNotHappenWithin 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

func ShouldNotHaveSameTypeAs(actual any, expected ...any) string

ShouldNotHaveSameTypeAs receives exactly two parameters and compares their underlying types for inequality.

func ShouldNotPanic

func ShouldNotPanic(actual any, expected ...any) (message string)

ShouldNotPanic receives a void, niladic function and expects to execute the function without any panic.

func ShouldNotPanicWith

func ShouldNotPanicWith(actual any, expected ...any) (message string)

ShouldNotPanicWith receives a void, niladic function and expects to recover a panic whose content differs from the second argument. If the expected value is an error and the recovered value is an error, errors.Is will be used to compare them.

func ShouldNotStartWith

func ShouldNotStartWith(actual any, expected ...any) string

ShouldNotStartWith receives exactly 2 string parameters and ensures that the first does not start with the second.

func ShouldPanic

func ShouldPanic(actual any, expected ...any) (message string)

ShouldPanic receives a void, niladic function and expects to recover a panic.

func ShouldPanicWith

func ShouldPanicWith(actual any, expected ...any) (message string)

ShouldPanicWith receives a void, niladic function and expects to recover a panic with the second argument as the content. If the expected value is an error and the recovered value is an error, errors.Is will be used to compare them.

func ShouldStartWith

func ShouldStartWith(actual any, expected ...any) string

ShouldStartWith receives exactly 2 string parameters and ensures that the first starts with the second.

func ShouldWrap

func ShouldWrap(actual any, expected ...any) string

ShouldWrap asserts that the first argument (which must be an error value) 'wraps' the second/final argument (which must also be an error value). It relies on errors.Is to make the determination (https://golang.org/pkg/errors/#Is).

Types

This section is empty.

Directories

Path Synopsis
internal
go-diff/diffmatchpatch
Package diffmatchpatch offers robust algorithms to perform the operations required for synchronizing plain text.
Package diffmatchpatch offers robust algorithms to perform the operations required for synchronizing plain text.
oglematchers
Package oglematchers provides a set of matchers useful in a testing or mocking framework.
Package oglematchers provides a set of matchers useful in a testing or mocking framework.
unit
package unit implements a light-weight x-Unit style testing framework.
package unit implements a light-weight x-Unit style testing framework.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL