assert

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: MIT Imports: 13 Imported by: 0

README

A stipped down version of the assert package from github.com/stretchr/testify

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Empty

func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool

Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either a slice or a channel with len == 0.

assert.Empty(t, obj)

func Emptyf

func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool

Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either a slice or a channel with len == 0.

assert.Emptyf(t, obj, "error message %s", "formatted")

func Equal

func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool

Equal asserts that two objects are equal.

assert.Equal(t, 123, 123)

Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses). Function equality cannot be determined and will always fail.

func EqualError

func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool

EqualError asserts that a function returned an error (i.e. not `nil`) and that it is equal to the provided error.

actualObj, err := SomeFunction()
assert.EqualError(t, err,  expectedErrorString)

func EqualErrorf

func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) bool

EqualErrorf asserts that a function returned an error (i.e. not `nil`) and that it is equal to the provided error.

actualObj, err := SomeFunction()
assert.EqualErrorf(t, err,  expectedErrorString, "error message %s", "formatted")

func Equalf

func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool

Equalf asserts that two objects are equal.

assert.Equalf(t, 123, 123, "error message %s", "formatted")

Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses). Function equality cannot be determined and will always fail.

func Error

func Error(t TestingT, err error, msgAndArgs ...interface{}) bool

Error asserts that a function returned an error (i.e. not `nil`).

  actualObj, err := SomeFunction()
  if assert.Error(t, err) {
	   assert.Equal(t, expectedError, err)
  }

func ErrorAs

func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) bool

ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. This is a wrapper for errors.As.

func ErrorAsf

func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) bool

ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. This is a wrapper for errors.As.

func ErrorIs

func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool

ErrorIs asserts that at least one of the errors in err's chain matches target. This is a wrapper for errors.Is.

func ErrorIsf

func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) bool

ErrorIsf asserts that at least one of the errors in err's chain matches target. This is a wrapper for errors.Is.

func Errorf

func Errorf(t TestingT, err error, msg string, args ...interface{}) bool

Errorf asserts that a function returned an error (i.e. not `nil`).

  actualObj, err := SomeFunction()
  if assert.Errorf(t, err, "error message %s", "formatted") {
	   assert.Equal(t, expectedErrorf, err)
  }

func Fail

func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool

Fail reports a failure through

func Failf

func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) bool

Failf reports a failure through

func False

func False(t TestingT, value bool, msgAndArgs ...interface{}) bool

False asserts that the specified value is false.

assert.False(t, myBool)

func Falsef

func Falsef(t TestingT, value bool, msg string, args ...interface{}) bool

Falsef asserts that the specified value is false.

assert.Falsef(t, myBool, "error message %s", "formatted")

func Greater

func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool

Greater asserts that the first element is greater than the second

assert.Greater(t, 2, 1)
assert.Greater(t, float64(2), float64(1))
assert.Greater(t, "b", "a")

func GreaterOrEqual

func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool

GreaterOrEqual asserts that the first element is greater than or equal to the second

assert.GreaterOrEqual(t, 2, 1)
assert.GreaterOrEqual(t, 2, 2)
assert.GreaterOrEqual(t, "b", "a")
assert.GreaterOrEqual(t, "b", "b")

func GreaterOrEqualf

func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool

GreaterOrEqualf asserts that the first element is greater than or equal to the second

assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted")
assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted")
assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted")
assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted")

func Greaterf

func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool

Greaterf asserts that the first element is greater than the second

assert.Greaterf(t, 2, 1, "error message %s", "formatted")
assert.Greaterf(t, float64(2), float64(1), "error message %s", "formatted")
assert.Greaterf(t, "b", "a", "error message %s", "formatted")

func InDelta

func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool

InDelta asserts that the two numerals are within delta of each other.

assert.InDelta(t, math.Pi, 22/7.0, 0.01)

func InDeltaMapValues

func InDeltaMapValues(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool

InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.

func InDeltaSlice

func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool

InDeltaSlice is the same as InDelta, except it compares two slices.

func InEpsilon

func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool

InEpsilon asserts that expected and actual have a relative error less than epsilon

func InEpsilonSlice

func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool

InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.

func JSONEq

func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool

JSONEq asserts that two JSON strings are equivalent.

assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)

func JSONEqf

func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool

JSONEqf asserts that two JSON strings are equivalent.

assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")

func Less

func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool

Less asserts that the first element is less than the second

assert.Less(t, 1, 2)
assert.Less(t, float64(1), float64(2))
assert.Less(t, "a", "b")

func LessOrEqual

func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool

LessOrEqual asserts that the first element is less than or equal to the second

assert.LessOrEqual(t, 1, 2)
assert.LessOrEqual(t, 2, 2)
assert.LessOrEqual(t, "a", "b")
assert.LessOrEqual(t, "b", "b")

func LessOrEqualf

func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool

LessOrEqualf asserts that the first element is less than or equal to the second

assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted")
assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted")
assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted")
assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted")

func Lessf

func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool

Lessf asserts that the first element is less than the second

assert.Lessf(t, 1, 2, "error message %s", "formatted")
assert.Lessf(t, float64(1), float64(2), "error message %s", "formatted")
assert.Lessf(t, "a", "b", "error message %s", "formatted")

func Negative

func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) bool

Negative asserts that the specified element is negative

assert.Negative(t, -1)
assert.Negative(t, -1.23)

func Negativef

func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) bool

Negativef asserts that the specified element is negative

assert.Negativef(t, -1, "error message %s", "formatted")
assert.Negativef(t, -1.23, "error message %s", "formatted")

func Nil

func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool

Nil asserts that the specified object is nil.

assert.Nil(t, err)

func Nilf

func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) bool

Nilf asserts that the specified object is nil.

assert.Nilf(t, err, "error message %s", "formatted")

func NoError

func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool

NoError asserts that a function returned no error (i.e. `nil`).

  actualObj, err := SomeFunction()
  if assert.NoError(t, err) {
	   assert.Equal(t, expectedObj, actualObj)
  }

func NoErrorf

func NoErrorf(t TestingT, err error, msg string, args ...interface{}) bool

NoErrorf asserts that a function returned no error (i.e. `nil`).

  actualObj, err := SomeFunction()
  if assert.NoErrorf(t, err, "error message %s", "formatted") {
	   assert.Equal(t, expectedObj, actualObj)
  }

func NotEmpty

func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool

NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either a slice or a channel with len == 0.

if assert.NotEmpty(t, obj) {
  assert.Equal(t, "two", obj[1])
}

func NotEmptyf

func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool

NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either a slice or a channel with len == 0.

if assert.NotEmptyf(t, obj, "error message %s", "formatted") {
  assert.Equal(t, "two", obj[1])
}

func NotEqual

func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool

NotEqual asserts that the specified values are NOT equal.

assert.NotEqual(t, obj1, obj2)

Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses).

func NotEqualf

func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool

NotEqualf asserts that the specified values are NOT equal.

assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted")

Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses).

func NotErrorIs

func NotErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool

NotErrorIs asserts that at none of the errors in err's chain matches target. This is a wrapper for errors.Is.

func NotErrorIsf

func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) bool

NotErrorIsf asserts that at none of the errors in err's chain matches target. This is a wrapper for errors.Is.

func NotNil

func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool

NotNil asserts that the specified object is not nil.

assert.NotNil(t, err)

func NotNilf

func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) bool

NotNilf asserts that the specified object is not nil.

assert.NotNilf(t, err, "error message %s", "formatted")

func NotZero

func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) bool

NotZero asserts that i is not the zero value for its type.

func ObjectsAreEqual

func ObjectsAreEqual(expected, actual interface{}) bool

ObjectsAreEqual determines if two objects are considered equal.

This function does no assertion of any kind.

func ObjectsAreEqualValues

func ObjectsAreEqualValues(expected, actual interface{}) bool

ObjectsAreEqualValues gets whether two objects are equal, or if their values are equal.

func Panics

func Panics(t TestingT, f func(), msgAndArgs ...interface{}) bool

Panics asserts that the code inside the specified f panics.

assert.Panics(t, func(){ GoCrazy() })

func Panicsf

func Panicsf(t TestingT, f func(), msg string, args ...interface{}) bool

Panicsf asserts that the code inside the specified f panics.

assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted")

func Positive

func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) bool

Positive asserts that the specified element is positive

assert.Positive(t, 1)
assert.Positive(t, 1.23)

func True

func True(t TestingT, value bool, msgAndArgs ...interface{}) bool

True asserts that the specified value is true.

assert.True(t, myBool)

func Truef

func Truef(t TestingT, value bool, msg string, args ...interface{}) bool

Truef asserts that the specified value is true.

assert.Truef(t, myBool, "error message %s", "formatted")

func Zero

func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) bool

Zero asserts that i is the zero value for its type.

Types

type TestingT

type TestingT interface {
	Errorf(format string, args ...interface{})
}

TestingT is an interface wrapper around *testing.T

Directories

Path Synopsis
Package difflib is a partial port of Python difflib module.
Package difflib is a partial port of Python difflib module.

Jump to

Keyboard shortcuts

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