Documentation ¶
Overview ¶
Package testutils contains convenient testing checkers that compare a produced value against an expected value (or condition). There are value checks like `CheckEqual(expected, produced, t)“, and checks that should run deferred like `defer ShouldPanic(t)`.
Index ¶
- func AsFloat(v interface{}) (rv float64, ok bool)
- func AsInteger(v interface{}) (int64, bool)
- func AsInterface(v interface{}) (rv interface{}, ok bool)
- func CheckContainsElements(expected interface{}, got interface{}, t *testing.T)
- func CheckEqual(expected interface{}, got interface{}, t *testing.T)
- func CheckEqualAndNoError(expected interface{}, got interface{}, gotError error, t *testing.T)
- func CheckEqualElements(expected interface{}, got interface{}, t *testing.T)
- func CheckError(got interface{}, t *testing.T)
- func CheckFalse(got bool, t *testing.T)
- func CheckFileExists(filename string, t *testing.T)
- func CheckFilesEqual(file1, file2 string, t *testing.T)
- func CheckMatches(expected interface{}, got string, t *testing.T)
- func CheckNil(got interface{}, t *testing.T)
- func CheckNotEqual(expected interface{}, got interface{}, t *testing.T)
- func CheckNotError(got interface{}, t *testing.T)
- func CheckNotNil(got interface{}, t *testing.T)
- func CheckNumericGreater(expected interface{}, got interface{}, t *testing.T)
- func CheckNumericLess(expected interface{}, got interface{}, t *testing.T)
- func CheckTrue(got bool, t *testing.T)
- func ShouldNotPanic(t *testing.T)
- func ShouldPanic(t *testing.T)
- type Tester
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsFloat ¶
AsFloat returns the argument as a 64 bit float and true if the argument is a float that fits into that type. Otherwise it returns 0, false
func AsInteger ¶
AsInteger returns the argument as a signed 64 bit integer and true if the argument is an integer that fits into that type. Otherwise it returns 0, false
func AsInterface ¶
func AsInterface(v interface{}) (rv interface{}, ok bool)
AsInterface returns the argument as an interface{}. This is useful when a value may be a reflect.Value and an operation does not work on such, but on the underlying real value albeit behind an interface{}.
func CheckContainsElements ¶
CheckContainsElements checks if one slice contains all elements of another slice irrespective of order and uniqueness.
func CheckEqual ¶
CheckEqual checks if two values are deeply equal and calls t.Fatalf if not
func CheckEqualAndNoError ¶
CheckEqualAndNoError checks there is no error, and that two values are deeply equal and calls t.Fatalf if not
func CheckEqualElements ¶
CheckEqualElements checks if two slices contains the exact same set of elements irrespective of order and uniqueness.
func CheckError ¶
CheckError checks if there is an error
func CheckFileExists ¶
CheckFileExists checks that given file name is for an existing regular file
func CheckFilesEqual ¶
CheckFilesEqual equals checks if the two files have the exact same contents.
func CheckMatches ¶
CheckMatches checks expected regular expression is matched by the given string and calls t.Fatalf if not
The expected regular expression can be either a *regexp.Regexp or a string that represents a valid regexp
func CheckNotEqual ¶
CheckNotEqual checks if two values are deeply equal and calls t.Fatalf if not
func CheckNotError ¶
CheckNotError checks if value is not an error
func CheckNotNil ¶
CheckNotNil checks if value is not nil
func CheckNumericGreater ¶
CheckNumericGreater checks if second value is greater than first. Comparisons are made regardless of bit size and an integer is equal to a float if casting it to a float makes it equal.
func CheckNumericLess ¶
CheckNumericLess checks if second value is less than first. Comparisons are made regardless of bit size and an integer is equal to a float if casting it to a float makes it equal.
func ShouldNotPanic ¶
ShouldNotPanic is used to assert that a function does not panic
func ShouldPanic ¶
ShouldPanic is used to assert that a function does panic
Types ¶
type Tester ¶
type Tester interface { // At sets index and returns this for convenient chaining as tt.At(i).CheckXXX() At(index int) Tester CheckEqual(expected interface{}, got interface{}) CheckNotEqual(expected interface{}, got interface{}) CheckNumericGreater(expected interface{}, got interface{}) CheckNumericLess(expected interface{}, got interface{}) CheckEqualAndNoError(expected interface{}, got interface{}, gotError error) CheckNil(got interface{}) CheckNotNil(got interface{}) CheckError(got error) CheckNotError(got error) CheckTrue(got bool) CheckFalse(got bool) CheckAfter(expected, got time.Time, add ...time.Duration) CheckAfterOrEqual(expected, got time.Time, add ...time.Duration) CheckBefore(expected, got time.Time, add ...time.Duration) CheckBeforeOrEqual(expected, got time.Time, add ...time.Duration) CheckMatches(expected interface{}, got string) Fatalf(fmt string, args ...interface{}) CheckTruef(predicate bool, fmt string, args ...interface{}) CheckStringSlicesEqual(expected, got []string) CheckTextEqual(expected, got string) }
Tester describes a testing context which can be modified to output an index for iterative testing