testutil

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Overview

Package testutil provides useful functions and helpers for writing tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertSamplesCountInCounter

func AssertSamplesCountInCounter(t assert.TestingT, counter prometheus.Counter, wantCount int) bool

AssertSamplesCountInCounter asserts that passed prometheus.Counter has proper value.

func AssertSamplesCountInHistogram

func AssertSamplesCountInHistogram(t assert.TestingT, hist prometheus.Histogram, wantSamplesCount int) bool

AssertSamplesCountInHistogram asserts that passed prometheus.Histogram contains the specified number of samples.

func DisableWrappingErrorInResponse

func DisableWrappingErrorInResponse()

DisableWrappingErrorInResponse disables expecting wrapped error ({"error": {"domain": "{domain}", ...} -> {"domain": "{domain}", ...}) in response body.

func EnableWrappingErrorInResponse

func EnableWrappingErrorInResponse()

EnableWrappingErrorInResponse enabled expecting wrapped error ({"domain": "{domain}", ...} -> {"error": {"domain": "{domain}", ...}) in response body.

func GetLocalAddrWithFreeTCPPort

func GetLocalAddrWithFreeTCPPort() string

GetLocalAddrWithFreeTCPPort returns 127.0.0.1:<free-tcp-port> address.

func GetLocalFreeTCPPort

func GetLocalFreeTCPPort() (int, error)

GetLocalFreeTCPPort returns free (not listening by somebody) TCP port on the 127.0.0.1 network interface.

func MustGetLocalFreeTCPPort

func MustGetLocalFreeTCPPort() int

MustGetLocalFreeTCPPort returns free (not listening by somebody) TCP port on the 127.0.0.1 network interface. It panics if an error occurs.

func RequireEmptyBodyInRecorder

func RequireEmptyBodyInRecorder(t require.TestingT, resp *httptest.ResponseRecorder)

RequireEmptyBodyInRecorder asserts that passing httptest.ResponseRecorder contains empty body.

func RequireEmptyBodyInResponse

func RequireEmptyBodyInResponse(t require.TestingT, resp *http.Response)

RequireEmptyBodyInResponse asserts that passing http.Responsecontains empty body.

func RequireErrorInRecorder

func RequireErrorInRecorder(t require.TestingT, resp *httptest.ResponseRecorder, wantHTTPCode int, wantErrDomain, wantErrCode string)

RequireErrorInRecorder asserts that passing httptest.ResponseRecorder contains error.

func RequireErrorInResponse

func RequireErrorInResponse(t require.TestingT, resp *http.Response, wantHTTPCode int, wantErrDomain, wantErrCode string)

RequireErrorInResponse asserts that passing http.Response contains the error.

func RequireErrorIsAny

func RequireErrorIsAny(t require.TestingT, err error, targets []error, msgAndArgs ...interface{})

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

func RequireJSONInRecorder

func RequireJSONInRecorder(t require.TestingT, resp *httptest.ResponseRecorder, want, dest interface{})

RequireJSONInRecorder asserts that passing httptest.ResponseRecorder contains the data in json format.

func RequireJSONInResponse

func RequireJSONInResponse(t require.TestingT, resp *http.Response, want, dest interface{})

RequireJSONInResponse asserts that passing http.Response contains the data in json format.

func RequireNoErrorInChannel

func RequireNoErrorInChannel(t require.TestingT, c <-chan error, msgAndArgs ...interface{})

RequireNoErrorInChannel asserts that there is an error in buffered channel.

func RequireNoWrappedErrorInRecorder

func RequireNoWrappedErrorInRecorder(
	t require.TestingT, resp *httptest.ResponseRecorder, wantHTTPCode int, wantErrDomain, wantErrCode string,
)

RequireNoWrappedErrorInRecorder asserts that passing httptest.ResponseRecorder contains no wrapped error.

func RequireNoWrappedErrorInResponse

func RequireNoWrappedErrorInResponse(t require.TestingT, resp *http.Response, wantHTTPCode int, wantErrDomain, wantErrCode string)

RequireNoWrappedErrorInResponse asserts that passing http.Response contains the no wrapped error.

func RequireSamplesCountInCounter

func RequireSamplesCountInCounter(t require.TestingT, counter prometheus.Counter, wantCount int)

RequireSamplesCountInCounter calls AssertSamplesCountInCounter and fail test immediately in case of error.

func RequireSamplesCountInHistogram

func RequireSamplesCountInHistogram(t require.TestingT, hist prometheus.Histogram, wantSamplesCount int)

RequireSamplesCountInHistogram calls AssertSamplesCountInHistogram and fail test immediately in case of error.

func RequireStringJSONInRecorder

func RequireStringJSONInRecorder(t require.TestingT, resp *httptest.ResponseRecorder, want string)

RequireStringJSONInRecorder asserts that passing httptest.ResponseRecorder contains the json string.

func RequireStringJSONInResponse

func RequireStringJSONInResponse(t require.TestingT, resp *http.Response, want string)

RequireStringJSONInResponse asserts that passing http.Response contains the json string.

func RequireWrappedErrorInRecorder

func RequireWrappedErrorInRecorder(
	t require.TestingT, resp *httptest.ResponseRecorder, wantHTTPCode int, wantErrDomain, wantErrCode string,
)

RequireWrappedErrorInRecorder asserts that passing httptest.ResponseRecorder contains wrapped error.

func RequireWrappedErrorInResponse

func RequireWrappedErrorInResponse(t require.TestingT, resp *http.Response, wantHTTPCode int, wantErrDomain, wantErrCode string)

RequireWrappedErrorInResponse asserts that passing http.Response contains the wrapped error.

func WaitListeningServer

func WaitListeningServer(addr string, timeout time.Duration) error

WaitListeningServer waits until the server is ready to accept TCP connection on the passing address.

func WaitListeningServerWithUnixSocket

func WaitListeningServerWithUnixSocket(unixSocketPath string, timeout time.Duration) error

WaitListeningServerWithUnixSocket waits until the server is ready to accept unix socket connection on the passing address.

func WaitPortAndListeningServer

func WaitPortAndListeningServer(host string, getPort func() int, timeout time.Duration) (int, error)

WaitPortAndListeningServer waits until port is known and the server is ready to accept TCP connection on the passing address.

Types

This section is empty.

Jump to

Keyboard shortcuts

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