tt

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertApproxDuration

func AssertApproxDuration(t *testing.T, tolerance time.Duration, v1, v2 time.Duration, format string, args ...interface{})

AssertApproxDuration checks if the durations v1 and v2 are close up to the tolerance specified. The format and args slice can be used for generating an appropriate error message if they are not.

func AssertApproxTime

func AssertApproxTime(t *testing.T, tolerance time.Duration, v1, v2 time.Time, format string, args ...interface{})

AssertApproxTime checks if the times v1 and v2 are close up to the tolerance specified. The format and args slice can be used for generating an appropriate error message if they are not.

func AssertContains added in v1.9.0

func AssertContains(t *testing.T, str string, substrs ...string)

AssertContains will check if the input text contains all the substrs specified on the substrs argument or fail with an appropriate error message.

func AssertEqual

func AssertEqual(t *testing.T, got interface{}, expected interface{}, msg ...interface{})

AssertEqual will compare the got argument with the expected argument and fail the test with an appropriate error message if they don't match.

func AssertErrContains

func AssertErrContains(t *testing.T, err error, substrs ...string)

AssertErrContains will first check if the error that the error indeed is not nil, and then check if its error message contains all the substrs specified on the substrs argument.

In case either assertion fails it will fail the test with an appropriate error message.

func AssertNoErr

func AssertNoErr(t *testing.T, err error)

AssertNoErr will check if the input error is nil, and if not it will fail the test with an appropriate error message.

func AssertNotEqual

func AssertNotEqual(t *testing.T, got interface{}, expected interface{}, msg ...interface{})

AssertNotEqual will compare the got argument with the expected argument and fail the test with an appropriate error message if they match.

func NextResponse added in v1.13.1

func NextResponse[T any](t *testing.T, resps *[]T) T

NextResponse works like the [].shift() function on JS:

it removes the first item from the slice and returns this element. If the slice is empty it will fail the test with an appropriate error message.

For example if you have the slice `s := []int{1,2,3}` and calls `v := tt.NextResponse(t, &s)`, `s` will contain: `[]int{2,3}` and `v` will contain `1`.

This function is meant to be used inside mocks when you need to specify a list of return values for sequential calls of the same mock function, for example if you want a mock function to only return an error on its third call:

sendErrors := []errors{nil, nil, fmt.Errorf("fakeErrMsg")}
myMock := MyMock{
    SendSomethingFn: func(something Something) error {
        return tt.NextResponse(t, &sendErrors)
    },
}

func PanicHandler

func PanicHandler(fn func()) (panicPayload interface{})

PanicHandler will run the input function and recover from any panics it might generate.

It will then save the panic payload and return it so it can be asserted by other functions on the test.

func ParseTime added in v1.4.9

func ParseTime(t *testing.T, timestr string) time.Time

func ToJSON added in v1.4.9

func ToJSON(t *testing.T, obj interface{}) []byte

Types

This section is empty.

Jump to

Keyboard shortcuts

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