testing

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallDetail

func CallDetail(msg []byte, fn interface{}, args ...interface{}) []byte

CallDetail print a function call shortly.

func PropVal

func PropVal(o reflect.Value, prop string) reflect.Value

PropVal returns property value of an object.

Types

type Assertions

type Assertions struct {
	A *assert.Assertions
	R []bool
}

https://github.com/stretchr/testify 的简单包装,支持链式调用 _codegen -output-package=testing -template=testify_gen.go.tmpl -include-format-funcs

func NewAssert

func NewAssert(t *testing.T) *Assertions

func (*Assertions) Condition

func (a *Assertions) Condition(comp assert.Comparison, msgAndArgs ...interface{}) *Assertions

Condition uses a Comparison to assert a complex condition.

func (*Assertions) Conditionf

func (a *Assertions) Conditionf(comp assert.Comparison, msg string, args ...interface{}) *Assertions

Conditionf uses a Comparison to assert a complex condition.

func (*Assertions) Contains

func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) *Assertions

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

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

func (*Assertions) Containsf

func (a *Assertions) Containsf(s interface{}, contains interface{}, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) DirExists

func (a *Assertions) DirExists(path string, msgAndArgs ...interface{}) *Assertions

DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.

func (*Assertions) DirExistsf

func (a *Assertions) DirExistsf(path string, msg string, args ...interface{}) *Assertions

DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.

func (*Assertions) ElementsMatch

func (a *Assertions) ElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) *Assertions

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.

a.ElementsMatch([1, 3, 2, 3], [1, 3, 3, 2])

func (*Assertions) ElementsMatchf

func (a *Assertions) ElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) *Assertions

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.

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

func (*Assertions) Empty

func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) *Assertions

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

a.Empty(obj)

func (*Assertions) Emptyf

func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) Equal

func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *Assertions

Equal asserts that two objects are equal.

a.Equal(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 (*Assertions) EqualError

func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) *Assertions

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

actualObj, err := SomeFunction()
a.EqualError(err,  expectedErrorString)

func (*Assertions) EqualErrorf

func (a *Assertions) EqualErrorf(theError error, errString string, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) EqualValues

func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *Assertions

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

a.EqualValues(uint32(123), int32(123))

func (*Assertions) EqualValuesf

func (a *Assertions) EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) Equalf

func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string, args ...interface{}) *Assertions

Equalf asserts that two objects are equal.

a.Equalf(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 (*Assertions) Error

func (a *Assertions) Error(err error, msgAndArgs ...interface{}) *Assertions

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

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

func (*Assertions) Errorf

func (a *Assertions) Errorf(err error, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) Eventually

func (a *Assertions) Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) *Assertions

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

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

func (*Assertions) Eventuallyf

func (a *Assertions) Eventuallyf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) Exactly

func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *Assertions

Exactly asserts that two objects are equal in value and type.

a.Exactly(int32(123), int64(123))

func (*Assertions) Exactlyf

func (a *Assertions) Exactlyf(expected interface{}, actual interface{}, msg string, args ...interface{}) *Assertions

Exactlyf asserts that two objects are equal in value and type.

a.Exactlyf(int32(123, "error message %s", "formatted"), int64(123))

func (*Assertions) Fail

func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) *Assertions

Fail reports a failure through

func (*Assertions) FailNow

func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) *Assertions

FailNow fails test

func (*Assertions) FailNowf

func (a *Assertions) FailNowf(failureMessage string, msg string, args ...interface{}) *Assertions

FailNowf fails test

func (*Assertions) Failf

func (a *Assertions) Failf(failureMessage string, msg string, args ...interface{}) *Assertions

Failf reports a failure through

func (*Assertions) False

func (a *Assertions) False(value bool, msgAndArgs ...interface{}) *Assertions

False asserts that the specified value is false.

a.False(myBool)

func (*Assertions) Falsef

func (a *Assertions) Falsef(value bool, msg string, args ...interface{}) *Assertions

Falsef asserts that the specified value is false.

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

func (*Assertions) FileExists

func (a *Assertions) FileExists(path string, msgAndArgs ...interface{}) *Assertions

FileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.

func (*Assertions) FileExistsf

func (a *Assertions) FileExistsf(path string, msg string, args ...interface{}) *Assertions

FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.

func (*Assertions) Greater

func (a *Assertions) Greater(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) *Assertions

Greater asserts that the first element is greater than the second

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

func (*Assertions) GreaterOrEqual

func (a *Assertions) GreaterOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) *Assertions

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

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

func (*Assertions) GreaterOrEqualf

func (a *Assertions) GreaterOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) Greaterf

func (a *Assertions) Greaterf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) *Assertions

Greaterf asserts that the first element is greater than the second

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

func (*Assertions) HTTPBodyContains

func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) *Assertions

HTTPBodyContains asserts that a specified handler returns a body that contains a string.

a.HTTPBodyContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")

Returns whether the assertion was successful (true) or not (false).

func (*Assertions) HTTPBodyContainsf

func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) *Assertions

HTTPBodyContainsf asserts that a specified handler returns a body that contains a string.

a.HTTPBodyContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")

Returns whether the assertion was successful (true) or not (false).

func (*Assertions) HTTPBodyNotContains

func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) *Assertions

HTTPBodyNotContains asserts that a specified handler returns a body that does not contain a string.

a.HTTPBodyNotContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")

Returns whether the assertion was successful (true) or not (false).

func (*Assertions) HTTPBodyNotContainsf

func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) *Assertions

HTTPBodyNotContainsf asserts that a specified handler returns a body that does not contain a string.

a.HTTPBodyNotContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")

Returns whether the assertion was successful (true) or not (false).

func (*Assertions) HTTPError

func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) *Assertions

HTTPError asserts that a specified handler returns an error status code.

a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}

Returns whether the assertion was successful (true) or not (false).

func (*Assertions) HTTPErrorf

func (a *Assertions) HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) *Assertions

HTTPErrorf asserts that a specified handler returns an error status code.

a.HTTPErrorf(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}

Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).

func (*Assertions) HTTPRedirect

func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) *Assertions

HTTPRedirect asserts that a specified handler returns a redirect status code.

a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}

Returns whether the assertion was successful (true) or not (false).

func (*Assertions) HTTPRedirectf

func (a *Assertions) HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) *Assertions

HTTPRedirectf asserts that a specified handler returns a redirect status code.

a.HTTPRedirectf(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}

Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).

func (*Assertions) HTTPSuccess

func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) *Assertions

HTTPSuccess asserts that a specified handler returns a success status code.

a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil)

Returns whether the assertion was successful (true) or not (false).

func (*Assertions) HTTPSuccessf

func (a *Assertions) HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) *Assertions

HTTPSuccessf asserts that a specified handler returns a success status code.

a.HTTPSuccessf(myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")

Returns whether the assertion was successful (true) or not (false).

func (*Assertions) Implements

func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) *Assertions

Implements asserts that an object is implemented by the specified interface.

a.Implements((*MyInterface)(nil), new(MyObject))

func (*Assertions) Implementsf

func (a *Assertions) Implementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{}) *Assertions

Implementsf asserts that an object is implemented by the specified interface.

a.Implementsf((*MyInterface, "error message %s", "formatted")(nil), new(MyObject))

func (*Assertions) InDelta

func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) *Assertions

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

a.InDelta(math.Pi, 22/7.0, 0.01)

func (*Assertions) InDeltaMapValues

func (a *Assertions) InDeltaMapValues(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) *Assertions

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

func (*Assertions) InDeltaMapValuesf

func (a *Assertions) InDeltaMapValuesf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) *Assertions

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

func (*Assertions) InDeltaSlice

func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) *Assertions

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

func (*Assertions) InDeltaSlicef

func (a *Assertions) InDeltaSlicef(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) *Assertions

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

func (*Assertions) InDeltaf

func (a *Assertions) InDeltaf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) InEpsilon

func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) *Assertions

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

func (*Assertions) InEpsilonSlice

func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) *Assertions

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

func (*Assertions) InEpsilonSlicef

func (a *Assertions) InEpsilonSlicef(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) *Assertions

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

func (*Assertions) InEpsilonf

func (a *Assertions) InEpsilonf(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) *Assertions

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

func (*Assertions) IsType

func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) *Assertions

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

func (*Assertions) IsTypef

func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) *Assertions

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

func (*Assertions) JSONEq

func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) *Assertions

JSONEq asserts that two JSON strings are equivalent.

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

func (*Assertions) JSONEqf

func (a *Assertions) JSONEqf(expected string, actual string, msg string, args ...interface{}) *Assertions

JSONEqf asserts that two JSON strings are equivalent.

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

func (*Assertions) Len

func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) *Assertions

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

a.Len(mySlice, 3)

func (*Assertions) Lenf

func (a *Assertions) Lenf(object interface{}, length int, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) Less

func (a *Assertions) Less(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) *Assertions

Less asserts that the first element is less than the second

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

func (*Assertions) LessOrEqual

func (a *Assertions) LessOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) *Assertions

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

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

func (*Assertions) LessOrEqualf

func (a *Assertions) LessOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) Lessf

func (a *Assertions) Lessf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) *Assertions

Lessf asserts that the first element is less than the second

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

func (*Assertions) Never

func (a *Assertions) Never(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) *Assertions

Never asserts that the given condition doesn't satisfy in waitFor time, periodically checking the target function each tick.

a.Never(func() bool { return false; }, time.Second, 10*time.Millisecond)

func (*Assertions) Neverf

func (a *Assertions) Neverf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) *Assertions

Neverf asserts that the given condition doesn't satisfy in waitFor time, periodically checking the target function each tick.

a.Neverf(func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")

func (*Assertions) Nil

func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) *Assertions

Nil asserts that the specified object is nil.

a.Nil(err)

func (*Assertions) Nilf

func (a *Assertions) Nilf(object interface{}, msg string, args ...interface{}) *Assertions

Nilf asserts that the specified object is nil.

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

func (*Assertions) NoDirExists

func (a *Assertions) NoDirExists(path string, msgAndArgs ...interface{}) *Assertions

NoDirExists checks whether a directory does not exist in the given path. It fails if the path points to an existing _directory_ only.

func (*Assertions) NoDirExistsf

func (a *Assertions) NoDirExistsf(path string, msg string, args ...interface{}) *Assertions

NoDirExistsf checks whether a directory does not exist in the given path. It fails if the path points to an existing _directory_ only.

func (*Assertions) NoError

func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) *Assertions

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

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

func (*Assertions) NoErrorf

func (a *Assertions) NoErrorf(err error, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) NoFileExists

func (a *Assertions) NoFileExists(path string, msgAndArgs ...interface{}) *Assertions

NoFileExists checks whether a file does not exist in a given path. It fails if the path points to an existing _file_ only.

func (*Assertions) NoFileExistsf

func (a *Assertions) NoFileExistsf(path string, msg string, args ...interface{}) *Assertions

NoFileExistsf checks whether a file does not exist in a given path. It fails if the path points to an existing _file_ only.

func (*Assertions) NotContains

func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) *Assertions

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

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

func (*Assertions) NotContainsf

func (a *Assertions) NotContainsf(s interface{}, contains interface{}, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) NotEmpty

func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) *Assertions

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 a.NotEmpty(obj) {
  assert.Equal(t, "two", obj[1])
}

func (*Assertions) NotEmptyf

func (a *Assertions) NotEmptyf(object interface{}, msg string, args ...interface{}) *Assertions

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 a.NotEmptyf(obj, "error message %s", "formatted") {
  assert.Equal(t, "two", obj[1])
}

func (*Assertions) NotEqual

func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *Assertions

NotEqual asserts that the specified values are NOT equal.

a.NotEqual(obj1, obj2)

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

func (*Assertions) NotEqualf

func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg string, args ...interface{}) *Assertions

NotEqualf asserts that the specified values are NOT equal.

a.NotEqualf(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 (*Assertions) NotNil

func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) *Assertions

NotNil asserts that the specified object is not nil.

a.NotNil(err)

func (*Assertions) NotNilf

func (a *Assertions) NotNilf(object interface{}, msg string, args ...interface{}) *Assertions

NotNilf asserts that the specified object is not nil.

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

func (*Assertions) NotPanics

func (a *Assertions) NotPanics(f assert.PanicTestFunc, msgAndArgs ...interface{}) *Assertions

NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.

a.NotPanics(func(){ RemainCalm() })

func (*Assertions) NotPanicsf

func (a *Assertions) NotPanicsf(f assert.PanicTestFunc, msg string, args ...interface{}) *Assertions

NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.

a.NotPanicsf(func(){ RemainCalm() }, "error message %s", "formatted")

func (*Assertions) NotRegexp

func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) *Assertions

NotRegexp asserts that a specified regexp does not match a string.

a.NotRegexp(regexp.MustCompile("starts"), "it's starting")
a.NotRegexp("^start", "it's not starting")

func (*Assertions) NotRegexpf

func (a *Assertions) NotRegexpf(rx interface{}, str interface{}, msg string, args ...interface{}) *Assertions

NotRegexpf asserts that a specified regexp does not match a string.

a.NotRegexpf(regexp.MustCompile("starts", "error message %s", "formatted"), "it's starting")
a.NotRegexpf("^start", "it's not starting", "error message %s", "formatted")

func (*Assertions) NotSame

func (a *Assertions) NotSame(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *Assertions

NotSame asserts that two pointers do not reference the same object.

a.NotSame(ptr1, ptr2)

Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.

func (*Assertions) NotSamef

func (a *Assertions) NotSamef(expected interface{}, actual interface{}, msg string, args ...interface{}) *Assertions

NotSamef asserts that two pointers do not reference the same object.

a.NotSamef(ptr1, ptr2, "error message %s", "formatted")

Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.

func (*Assertions) NotSubset

func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) *Assertions

NotSubset asserts that the specified list(array, slice...) contains not all elements given in the specified subset(array, slice...).

a.NotSubset([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")

func (*Assertions) NotSubsetf

func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) *Assertions

NotSubsetf asserts that the specified list(array, slice...) contains not all elements given in the specified subset(array, slice...).

a.NotSubsetf([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted")

func (*Assertions) NotZero

func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) *Assertions

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

func (*Assertions) NotZerof

func (a *Assertions) NotZerof(i interface{}, msg string, args ...interface{}) *Assertions

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

func (*Assertions) Panics

func (a *Assertions) Panics(f assert.PanicTestFunc, msgAndArgs ...interface{}) *Assertions

Panics asserts that the code inside the specified PanicTestFunc panics.

a.Panics(func(){ GoCrazy() })

func (*Assertions) PanicsWithError

func (a *Assertions) PanicsWithError(errString string, f assert.PanicTestFunc, msgAndArgs ...interface{}) *Assertions

PanicsWithError asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value is an error that satisfies the EqualError comparison.

a.PanicsWithError("crazy error", func(){ GoCrazy() })

func (*Assertions) PanicsWithErrorf

func (a *Assertions) PanicsWithErrorf(errString string, f assert.PanicTestFunc, msg string, args ...interface{}) *Assertions

PanicsWithErrorf asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value is an error that satisfies the EqualError comparison.

a.PanicsWithErrorf("crazy error", func(){ GoCrazy() }, "error message %s", "formatted")

func (*Assertions) PanicsWithValue

func (a *Assertions) PanicsWithValue(expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) *Assertions

PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value equals the expected panic value.

a.PanicsWithValue("crazy error", func(){ GoCrazy() })

func (*Assertions) PanicsWithValuef

func (a *Assertions) PanicsWithValuef(expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) *Assertions

PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value equals the expected panic value.

a.PanicsWithValuef("crazy error", func(){ GoCrazy() }, "error message %s", "formatted")

func (*Assertions) Panicsf

func (a *Assertions) Panicsf(f assert.PanicTestFunc, msg string, args ...interface{}) *Assertions

Panicsf asserts that the code inside the specified PanicTestFunc panics.

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

func (*Assertions) Regexp

func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) *Assertions

Regexp asserts that a specified regexp matches a string.

a.Regexp(regexp.MustCompile("start"), "it's starting")
a.Regexp("start...$", "it's not starting")

func (*Assertions) Regexpf

func (a *Assertions) Regexpf(rx interface{}, str interface{}, msg string, args ...interface{}) *Assertions

Regexpf asserts that a specified regexp matches a string.

a.Regexpf(regexp.MustCompile("start", "error message %s", "formatted"), "it's starting")
a.Regexpf("start...$", "it's not starting", "error message %s", "formatted")

func (*Assertions) Same

func (a *Assertions) Same(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *Assertions

Same asserts that two pointers reference the same object.

a.Same(ptr1, ptr2)

Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.

func (*Assertions) Samef

func (a *Assertions) Samef(expected interface{}, actual interface{}, msg string, args ...interface{}) *Assertions

Samef asserts that two pointers reference the same object.

a.Samef(ptr1, ptr2, "error message %s", "formatted")

Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.

func (*Assertions) Subset

func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) *Assertions

Subset asserts that the specified list(array, slice...) contains all elements given in the specified subset(array, slice...).

a.Subset([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")

func (*Assertions) Subsetf

func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) *Assertions

Subsetf asserts that the specified list(array, slice...) contains all elements given in the specified subset(array, slice...).

a.Subsetf([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted")

func (*Assertions) True

func (a *Assertions) True(value bool, msgAndArgs ...interface{}) *Assertions

True asserts that the specified value is true.

a.True(myBool)

func (*Assertions) Truef

func (a *Assertions) Truef(value bool, msg string, args ...interface{}) *Assertions

Truef asserts that the specified value is true.

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

func (*Assertions) WithinDuration

func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) *Assertions

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

a.WithinDuration(time.Now(), time.Now(), 10*time.Second)

func (*Assertions) WithinDurationf

func (a *Assertions) WithinDurationf(expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) *Assertions

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

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

func (*Assertions) YAMLEq

func (a *Assertions) YAMLEq(expected string, actual string, msgAndArgs ...interface{}) *Assertions

YAMLEq asserts that two YAML strings are equivalent.

func (*Assertions) YAMLEqf

func (a *Assertions) YAMLEqf(expected string, actual string, msg string, args ...interface{}) *Assertions

YAMLEqf asserts that two YAML strings are equivalent.

func (*Assertions) Zero

func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) *Assertions

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

func (*Assertions) Zerof

func (a *Assertions) Zerof(i interface{}, msg string, args ...interface{}) *Assertions

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

type FakeHandler

type FakeHandler struct {
	RequestReceived *http.Request
	RequestBody     string
	StatusCode      int
	ResponseBody    string
	// For logging - you can use a *testing.T
	// This will keep log messages associated with the test.
	T LogInterface

	SkipRequestFn func(verb string, url url.URL) bool
	// contains filtered or unexported fields
}

FakeHandler is to assist in testing HTTP requests. Notice that FakeHandler is not thread safe and you must not direct traffic to except for the request you want to test. You can do this by hiding it in an http.ServeMux.

func (*FakeHandler) ServeHTTP

func (f *FakeHandler) ServeHTTP(response http.ResponseWriter, request *http.Request)

func (*FakeHandler) SetResponseBody

func (f *FakeHandler) SetResponseBody(responseBody string)

func (*FakeHandler) ValidateRequest

func (f *FakeHandler) ValidateRequest(t TestInterface, expectedPath, expectedMethod string, body *string)

ValidateRequest verifies that FakeHandler received a request with expected path, method, and body.

func (*FakeHandler) ValidateRequestCount

func (f *FakeHandler) ValidateRequestCount(t TestInterface, count int) bool

type Frame

type Frame uintptr

Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.

func (Frame) Format

func (f Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%n    <funcname>
%v    <file>:<line>

Format accepts flags that alter the printing of some verbs, as follows:

%+v   equivalent to <funcname>\n\t<file>:<line>

type LogInterface

type LogInterface interface {
	Logf(format string, args ...interface{})
}

LogInterface is a simple interface to allow injection of Logf to report serving errors.

type TestCase

type TestCase struct {
	// contains filtered or unexported fields
}

TestCase represents a test case.

func (*TestCase) Call

func (p *TestCase) Call(fn interface{}, args ...interface{}) (e *TestCase)

Call calls a function.

func (*TestCase) Equal

func (p *TestCase) Equal(v interface{}) *TestCase

Equal checks current output value.

func (*TestCase) Init

func (p *TestCase) Init(result ...interface{}) *TestCase

Init sets output parameters.

func (*TestCase) Next

func (p *TestCase) Next() *TestCase

Next sets current output value to next output parameter.

func (*TestCase) Panic

func (p *TestCase) Panic(panicMsg ...interface{}) *TestCase

Panic checks if function call panics or not. Panic(v) means function call panics with `v`. If v == nil, it means we don't care any detail information about panic.

func (*TestCase) PropEqual

func (p *TestCase) PropEqual(prop string, v interface{}) *TestCase

PropEqual checks property of current output value.

func (*TestCase) With

func (p *TestCase) With(i int) *TestCase

With sets current output value to check.

type TestInterface

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

TestInterface is a simple interface providing Errorf, to make injection for testing easier (insert 'yo dawg' meme here).

type Testing

type Testing struct {
	// contains filtered or unexported fields
}

Testing represents a testing object.

func New

func New(t *testing.T) *Testing

New creates a testing object.

func (*Testing) Call

func (p *Testing) Call(fn interface{}, args ...interface{}) *TestCase

Call creates a test case, and then calls a function.

func (*Testing) Case

func (p *Testing) Case(name string, result ...interface{}) *TestCase

Case creates a test case and sets its output parameters.

func (*Testing) New

func (p *Testing) New(name string) *TestCase

New creates a test case.

Jump to

Keyboard shortcuts

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