Documentation ¶
Overview ¶
Package testutil provides useful functions and helpers for writing tests.
Index ¶
- func AssertSamplesCountInCounter(t assert.TestingT, counter prometheus.Counter, wantCount int) bool
- func AssertSamplesCountInHistogram(t assert.TestingT, hist prometheus.Histogram, wantSamplesCount int) bool
- func DisableWrappingErrorInResponse()
- func EnableWrappingErrorInResponse()
- func GetLocalAddrWithFreeTCPPort() string
- func GetLocalFreeTCPPort() (int, error)
- func MustGetLocalFreeTCPPort() int
- func RequireEmptyBodyInRecorder(t require.TestingT, resp *httptest.ResponseRecorder)
- func RequireEmptyBodyInResponse(t require.TestingT, resp *http.Response)
- func RequireErrorInRecorder(t require.TestingT, resp *httptest.ResponseRecorder, wantHTTPCode int, ...)
- func RequireErrorInResponse(t require.TestingT, resp *http.Response, wantHTTPCode int, ...)
- func RequireErrorIsAny(t require.TestingT, err error, targets []error, msgAndArgs ...interface{})
- func RequireJSONInRecorder(t require.TestingT, resp *httptest.ResponseRecorder, want, dest interface{})
- func RequireJSONInResponse(t require.TestingT, resp *http.Response, want, dest interface{})
- func RequireNoErrorInChannel(t require.TestingT, c <-chan error, msgAndArgs ...interface{})
- func RequireNoWrappedErrorInRecorder(t require.TestingT, resp *httptest.ResponseRecorder, wantHTTPCode int, ...)
- func RequireNoWrappedErrorInResponse(t require.TestingT, resp *http.Response, wantHTTPCode int, ...)
- func RequireSamplesCountInCounter(t require.TestingT, counter prometheus.Counter, wantCount int)
- func RequireSamplesCountInHistogram(t require.TestingT, hist prometheus.Histogram, wantSamplesCount int)
- func RequireStringJSONInRecorder(t require.TestingT, resp *httptest.ResponseRecorder, want string)
- func RequireStringJSONInResponse(t require.TestingT, resp *http.Response, want string)
- func RequireWrappedErrorInRecorder(t require.TestingT, resp *httptest.ResponseRecorder, wantHTTPCode int, ...)
- func RequireWrappedErrorInResponse(t require.TestingT, resp *http.Response, wantHTTPCode int, ...)
- func WaitListeningServer(addr string, timeout time.Duration) error
- func WaitListeningServerWithUnixSocket(unixSocketPath string, timeout time.Duration) error
- func WaitPortAndListeningServer(host string, getPort func() int, timeout time.Duration) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertSamplesCountInCounter ¶
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 ¶
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 ¶
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 ¶
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 ¶
RequireJSONInResponse asserts that passing http.Response contains the data in json format.
func RequireNoErrorInChannel ¶
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 ¶
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 ¶
WaitListeningServer waits until the server is ready to accept TCP connection on the passing address.
func WaitListeningServerWithUnixSocket ¶
WaitListeningServerWithUnixSocket waits until the server is ready to accept unix socket connection on the passing address.
Types ¶
This section is empty.