require

package
v1.12.0-cloud Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{})

Contains asserts that the specified string, list(array, slice...) or map contains the specified substring or element.

assert.Contains(t, "Hello World", "World")
assert.Contains(t, ["Hello", "World"], "World")
assert.Contains(t, {"Hello": "World"}, "Hello")

func Containsf

func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{})

Containsf asserts that the specified string, list(array, slice...) or map contains the specified substring or element.

assert.Containsf(t, "Hello World", "World", "error message %s", "formatted")
assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted")
assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted")

func ElementsMatch

func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{})

ElementsMatch asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.

assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2])

func ElementsMatchf

func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{})

ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.

assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")

func Equal

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

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{})

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{})

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 EqualValues

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

EqualValues asserts that two objects are equal or convertable to the same types and equal.

assert.EqualValues(t, uint32(123), int32(123))

func EqualValuesf

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

EqualValuesf asserts that two objects are equal or convertable to the same types and equal.

assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted")

func Equalf

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

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{})

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 ErrorContains

func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{})

ErrorContains asserts that a function returned an error (i.e. not `nil`) and that the error contains the specified substring.

actualObj, err := SomeFunction()
assert.ErrorContains(t, err,  expectedErrorSubString)

func ErrorContainsf

func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{})

ErrorContainsf asserts that a function returned an error (i.e. not `nil`) and that the error contains the specified substring.

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

func Errorf

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

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 Eventually

func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{})

Eventually asserts that given condition will be met in waitFor time, periodically checking target function each tick.

assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)

func Eventuallyf

func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{})

Eventuallyf asserts that given condition will be met in waitFor time, periodically checking target function each tick.

assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")

func Fail

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

Fail reports a failure through

func FailNow

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

FailNow fails test

func FailNowf

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

FailNowf fails test

func Failf

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

Failf reports a failure through

func False

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

False asserts that the specified value is false.

assert.False(t, myBool)

func Falsef

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

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{})

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{})

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{})

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{})

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 interface{}, actual interface{}, delta float64, msgAndArgs ...interface{})

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

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

func InDeltaf

func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{})

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

assert.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted")

func IsType

func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{})

IsType asserts that the specified objects are of the same type.

func IsTypef

func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{})

IsTypef asserts that the specified objects are of the same type.

func Len

func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{})

Len asserts that the specified object has specific length. Len also fails if the object has a type that len() not accept.

assert.Len(t, mySlice, 3)

func Lenf

func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{})

Lenf asserts that the specified object has specific length. Lenf also fails if the object has a type that len() not accept.

assert.Lenf(t, mySlice, 3, "error message %s", "formatted")

func Less

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

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{})

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{})

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{})

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{})

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{})

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{})

Nil asserts that the specified object is nil.

assert.Nil(t, err)

func Nilf

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

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{})

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{})

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 NotContains

func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{})

NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.

assert.NotContains(t, "Hello World", "Earth")
assert.NotContains(t, ["Hello", "World"], "Earth")
assert.NotContains(t, {"Hello": "World"}, "Earth")

func NotContainsf

func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{})

NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.

assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted")
assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted")
assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted")

func NotEqual

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

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 NotEqualValues

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

NotEqualValues asserts that two objects are not equal even when converted to the same type

assert.NotEqualValues(t, obj1, obj2)

func NotEqualValuesf

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

NotEqualValuesf asserts that two objects are not equal even when converted to the same type

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

func NotEqualf

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

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 NotNil

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

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{})

NotNilf asserts that the specified object is not nil.

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

func Positive

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

Positive asserts that the specified element is positive

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

func Positivef

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

Positivef asserts that the specified element is positive

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

func True

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

True asserts that the specified value is true.

assert.True(t, myBool)

func Truef

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

Truef asserts that the specified value is true.

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

func WithinDuration

func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{})

WithinDuration asserts that the two times are within duration delta of each other.

assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)

func WithinDurationf

func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{})

WithinDurationf asserts that the two times are within duration delta of each other.

assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")

Types

type TestingT

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

TestingT is an interface wrapper around *testing.T

Jump to

Keyboard shortcuts

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