assert

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: BSD-3-Clause Imports: 15 Imported by: 1

README

assert

Go assertion package for testing framework

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallerInfo

func CallerInfo() []string

func Contains

func Contains(t ITesting, result, expected interface{}, message ...interface{}) bool

func Containsf

func Containsf(t ITesting, result, expected interface{}, msg string, args ...interface{}) bool

func DeepEqual

func DeepEqual(t ITesting, result, expected interface{}, message ...interface{}) bool

func DidPanic

func DidPanic(f PanicTestFunc) (bool, interface{}, string)

func DirExists

func DirExists(t ITesting, path string, message ...interface{}) bool

func DirExistsf

func DirExistsf(t ITesting, path string, msg string, args ...interface{}) bool

func Empty

func Empty(t ITesting, result interface{}, message ...interface{}) bool

func Emptyf

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

func Equal

func Equal(t ITesting, result, expected interface{}, message ...interface{}) bool

func EqualError

func EqualError(t ITesting, result error, errorMessage string, message ...interface{}) bool

func EqualErrorf

func EqualErrorf(t ITesting, result error, errorMessage string, msg string, args ...interface{}) bool

func Equalf

func Equalf(t ITesting, result, expected interface{}, msg string, args ...interface{}) bool

func Error

func Error(t ITesting, result error, message ...interface{}) bool

func ErrorAs

func ErrorAs(t ITesting, result, expected error, message ...interface{}) bool

func ErrorAsf

func ErrorAsf(t ITesting, result, expected error, msg string, args ...interface{}) bool

func ErrorIs

func ErrorIs(t ITesting, result, expected error, message ...interface{}) bool

func ErrorIsf

func ErrorIsf(t ITesting, result, expected error, msg string, args ...interface{}) bool

func Errorf

func Errorf(t ITesting, result error, msg string, args ...interface{}) bool

func Eventually

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

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 ITesting, condition func() bool, waitFor, tick time.Duration, msg string, args ...interface{}) bool

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 Exactly

func Exactly(t ITesting, result, expected interface{}, message ...interface{}) bool

func Exactlyf

func Exactlyf(t ITesting, result, expected interface{}, msg string, args ...interface{}) bool

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

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

func Fail

func Fail(t ITesting, failureMessage string, message ...interface{}) bool

func FailNow

func FailNow(t ITesting, failureMessage string, message ...interface{}) bool

func FailNowf

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

func Failf

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

func False

func False(t ITesting, result interface{}, message ...interface{}) bool

func Falsef

func Falsef(t ITesting, result interface{}, msg string, args ...interface{}) bool

func FileExists

func FileExists(t ITesting, path string, message ...interface{}) bool

func FileNotExists

func FileNotExists(t ITesting, path string, message ...interface{}) bool

func HttpBody

func HttpBody(handler http.HandlerFunc, method, url string, values url.Values) string

HttpBody is a helper that returns HTTP body of the response. It returns empty string if building a new request fails.

func HttpBodyContains

func HttpBodyContains(t ITesting, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, message ...interface{}) bool

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

assert.HttpBodyContains(t, myHandler, http.MethodGet, "www.google.com", nil, "I'm Feeling Lucky")

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

func HttpBodyNotContains

func HttpBodyNotContains(t ITesting, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, message ...interface{}) bool

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

assert.HttpBodyNotContains(t, myHandler, http.MethodGet, "www.google.com", nil, "I'm Feeling Lucky")

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

func HttpError

func HttpError(t ITesting, handler http.HandlerFunc, method, url string, values url.Values, message ...interface{}) bool

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

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

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

func HttpRedirect

func HttpRedirect(t ITesting, handler http.HandlerFunc, method, url string, values url.Values, message ...interface{}) bool

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

assert.HttpRedirect(t, myHandler, http.MethodGet, "/a/b/c", url.Values{"a": []string{"b", "c"}}

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

func HttpStatusCode

func HttpStatusCode(t ITesting, handler http.HandlerFunc, method, url string, values url.Values, statuscode int, message ...interface{}) bool

HttpStatusCode asserts that a specified handler returns a specified status code.

assert.HttpStatusCode(t, myHandler, http.MethodGet, "/notImplemented", nil, 501)

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

func HttpSuccess

func HttpSuccess(t ITesting, handler http.HandlerFunc, method, url string, values url.Values, message ...interface{}) bool

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

assert.HttpSuccess(t, myHandler, "POST", "http://www.google.com", nil)

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

func IsEmpty

func IsEmpty(result interface{}) bool

func Len

func Len(t ITesting, object interface{}, length int, message ...interface{}) bool

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 Never

func Never(t ITesting, condition func() bool, waitFor, tick time.Duration, message ...interface{}) bool

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

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

func Nil

func Nil(t ITesting, result interface{}, message ...interface{}) bool

Nil asserts that the given parameter equals nil.

func NoDirExists

func NoDirExists(t ITesting, path string, message ...interface{}) bool

func NoDirExistsf

func NoDirExistsf(t ITesting, path string, msg string, args ...interface{}) bool

func NoError

func NoError(t ITesting, result error, message ...interface{}) bool

func NotContains

func NotContains(t ITesting, result, expected interface{}, message ...interface{}) bool

func NotContainsf

func NotContainsf(t ITesting, result, expected interface{}, msg string, args ...interface{}) bool

func NotEmpty

func NotEmpty(t ITesting, result interface{}, message ...interface{}) bool

func NotEmptyf

func NotEmptyf(t ITesting, result interface{}, msg string, args ...interface{}) bool

func NotEqual

func NotEqual(t ITesting, result, expected interface{}, message ...interface{}) bool

func NotErrorIs

func NotErrorIs(t ITesting, result, expected error, message ...interface{}) bool

func NotNil

func NotNil(t ITesting, result interface{}, message ...interface{}) bool

NotNil asserts that the given parameter does not equal nil.

func NotPanics

func NotPanics(t ITesting, f PanicTestFunc, message ...interface{}) bool

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

assert.NotPanics(t, func(){ RemainCalm() })

func Panics

func Panics(t ITesting, f PanicTestFunc, message ...interface{}) bool

Panics asserts that the code inside the specified PanicTestFunc panics.

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

func PanicsWithError

func PanicsWithError(t ITesting, errorMessage string, f PanicTestFunc, message ...interface{}) bool

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

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

func PanicsWithValue

func PanicsWithValue(t ITesting, expected interface{}, f PanicTestFunc, message ...interface{}) bool

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

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

func True

func True(t ITesting, result interface{}, message ...interface{}) bool

func Truef

func Truef(t ITesting, result interface{}, msg string, args ...interface{}) bool

func WithinDuration

func WithinDuration(t ITesting, expected, actual time.Time, delta time.Duration, message ...interface{}) bool

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

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

Types

type Assertions

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

func New

func New(t ITesting) *Assertions

func (*Assertions) Contains

func (a *Assertions) Contains(result, expected interface{}, message ...interface{}) bool

func (*Assertions) Containsf

func (a *Assertions) Containsf(result, expected interface{}, msg string, args ...interface{}) bool

func (*Assertions) DeepEqual

func (a *Assertions) DeepEqual(result, expected interface{}, message ...interface{}) bool

func (*Assertions) DirExists

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

func (*Assertions) DirExistsf

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

func (*Assertions) Empty

func (a *Assertions) Empty(result interface{}, message ...interface{}) bool

func (*Assertions) Emptyf

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

func (*Assertions) Equal

func (a *Assertions) Equal(result, expected interface{}, message ...interface{}) bool

func (*Assertions) EqualError

func (a *Assertions) EqualError(result error, errMessage string, message ...interface{}) bool

func (*Assertions) EqualErrorf

func (a *Assertions) EqualErrorf(result error, errorMessage string, msg string, args ...interface{}) bool

func (*Assertions) Equalf

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

func (*Assertions) Error

func (a *Assertions) Error(result error, message ...interface{}) bool

func (*Assertions) ErrorAs

func (a *Assertions) ErrorAs(result, expected error, message ...interface{}) bool

func (*Assertions) ErrorAsf

func (a *Assertions) ErrorAsf(result, expected error, msg string, args ...interface{}) bool

func (*Assertions) ErrorIs

func (a *Assertions) ErrorIs(result, expected error, message ...interface{}) bool

func (*Assertions) ErrorIsf

func (a *Assertions) ErrorIsf(result, expected error, msg string, args ...interface{}) bool

func (*Assertions) Errorf

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

func (*Assertions) Eventually

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

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 (*Assertions) Eventuallyf

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

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 (*Assertions) Exactly

func (a *Assertions) Exactly(result, expected interface{}, message ...interface{}) bool

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

assert.Exactly(t, int32(123), int64(123))

func (*Assertions) Exactlyf

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

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

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

func (*Assertions) Fail

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

func (*Assertions) FailNow

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

func (*Assertions) FailNowf

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

func (*Assertions) Failf

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

func (*Assertions) False

func (a *Assertions) False(result interface{}, message ...interface{}) bool

func (*Assertions) Falsef

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

func (*Assertions) FileExists

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

func (*Assertions) FileNotExists

func (a *Assertions) FileNotExists(path string, message ...interface{}) bool

func (*Assertions) HttpBodyContains

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

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

assert.HttpBodyContains(t, myHandler, http.MethodGet, "www.google.com", nil, "I'm Feeling Lucky")

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

func (*Assertions) HttpBodyNotContains

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

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

assert.HttpBodyNotContains(t, myHandler, http.MethodGet, "www.google.com", nil, "I'm Feeling Lucky")

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

func (*Assertions) HttpError

func (a *Assertions) HttpError(handler http.HandlerFunc, method, url string, values url.Values, message ...interface{}) bool

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

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

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

func (*Assertions) HttpRedirect

func (a *Assertions) HttpRedirect(handler http.HandlerFunc, method, url string, values url.Values, message ...interface{}) bool

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

assert.HttpRedirect(t, myHandler, http.MethodGet, "/a/b/c", url.Values{"a": []string{"b", "c"}}

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

func (*Assertions) HttpStatusCode

func (a *Assertions) HttpStatusCode(handler http.HandlerFunc, method, url string, values url.Values, statuscode int, message ...interface{}) bool

HttpStatusCode asserts that a specified handler returns a specified status code.

assert.HttpStatusCode(t, myHandler, http.MethodGet, "/notImplemented", nil, 501)

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

func (*Assertions) HttpSuccess

func (a *Assertions) HttpSuccess(handler http.HandlerFunc, method, url string, values url.Values, message ...interface{}) bool

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

assert.HttpSuccess(t, myHandler, "POST", "http://www.google.com", nil)

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

func (*Assertions) IsEmpty

func (a *Assertions) IsEmpty(result interface{}) bool

func (*Assertions) Len

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

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 (*Assertions) Never

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

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

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

func (*Assertions) Nil

func (a *Assertions) Nil(result interface{}, message ...interface{}) bool

Nil asserts that the given parameter equals nil.

func (*Assertions) NoDirExists

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

func (*Assertions) NoDirExistsf

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

func (*Assertions) NoError

func (a *Assertions) NoError(result error, message ...interface{}) bool

func (*Assertions) NotContains

func (a *Assertions) NotContains(result, expected interface{}, message ...interface{}) bool

func (*Assertions) NotContainsf

func (a *Assertions) NotContainsf(result, expected interface{}, msg string, args ...interface{}) bool

func (*Assertions) NotEmpty

func (a *Assertions) NotEmpty(result interface{}, message ...interface{}) bool

func (*Assertions) NotEmptyf

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

func (*Assertions) NotEqual

func (a *Assertions) NotEqual(result, expected interface{}, message ...interface{}) bool

func (*Assertions) NotErrorIs

func (a *Assertions) NotErrorIs(result, expected error, message ...interface{}) bool

func (*Assertions) NotNil

func (a *Assertions) NotNil(result interface{}, message ...interface{}) bool

NotNil asserts that the given parameter does not equal nil.

func (*Assertions) NotPanics

func (a *Assertions) NotPanics(f PanicTestFunc, message ...interface{}) bool

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

assert.NotPanics(t, func(){ RemainCalm() })

func (*Assertions) Panics

func (a *Assertions) Panics(f PanicTestFunc, message ...interface{}) bool

Panics asserts that the code inside the specified PanicTestFunc panics.

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

func (*Assertions) PanicsWithError

func (a *Assertions) PanicsWithError(errorMessage string, f PanicTestFunc, message ...interface{}) bool

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

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

func (*Assertions) PanicsWithValue

func (a *Assertions) PanicsWithValue(expected interface{}, f PanicTestFunc, message ...interface{}) bool

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

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

func (*Assertions) True

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

func (*Assertions) Truef

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

func (*Assertions) WithinDuration

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

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

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

type IFailNow

type IFailNow interface {
	FailNow()
}

type ITesting

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

type ITestingHelper

type ITestingHelper interface {
	Helper()
}

type PanicTestFunc

type PanicTestFunc func()

PanicTestFunc defines a func that should be passed to assert.Panics and assert.NotPanics methods, and represents a simple func that takes no arguments, and returns nothing.

Jump to

Keyboard shortcuts

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