Documentation
¶
Overview ¶
Package testutil implements helper functions for more convenient testing and may be imported in '_test.go' files only. Usage of some of these functions would have to be replaced by the ones provided by the official testing toolkit packages, should they decide to include helper functions of similar logic and kind.
Index ¶
- func AssertEqualError(t *testing.T, exp, err error)
- func AssertFilterEqual(t *testing.T, v1, v2 interface{}, ignoreTypes []interface{})
- func MockHTTP() (*http.Client, *httpmock.MockTransport)
- func QueryResponder(t *testing.T, resp httpmock.Responder, q url.Values) httpmock.Responder
- func RequireEqualError(t *testing.T, exp, err error)
- func RequireFilterEqual(t *testing.T, v1, v2 interface{}, ignoreTypes []interface{})
- type RoundTripperMock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertEqualError ¶
AssertEqualError uses testify's assert package to check if errors are equal or, if assert.AnError is expected, whether an error exists or not.
func AssertFilterEqual ¶
AssertFilterEqual asserts that two objects are equal. All ignored types found on any of the provided objects will not be compared.
func MockHTTP ¶
func MockHTTP() (*http.Client, *httpmock.MockTransport)
MockHTTP returns mocked http environment.
func QueryResponder ¶
QueryResponder asserts the required query values are present in the request.
func RequireEqualError ¶
RequireEqualError uses testify's require package to check if errors are equal or, if assert.AnError is expected, whether an error exists or not.
func RequireFilterEqual ¶
RequireFilterEqual asserts that two objects are equal. All ignored types found on any of the provided objects will not be compared.
Types ¶
type RoundTripperMock ¶
type RoundTripperMock struct { // RoundTripFunc mocks the RoundTrip method. RoundTripFunc func(in1 *http.Request) (*http.Response, error) // contains filtered or unexported fields }
RoundTripperMock is a mock implementation of http.RoundTripper.
func TestSomethingThatUsesRoundTripper(t *testing.T) { // make and configure a mocked http.RoundTripper mockedRoundTripper := &RoundTripperMock{ RoundTripFunc: func(in1 *http.Request) (*http.Response, error) { panic("mock out the RoundTrip method") }, } // use mockedRoundTripper in code that requires RoundTripper // and then make assertions. }
func (*RoundTripperMock) RoundTripCalls ¶
func (mock *RoundTripperMock) RoundTripCalls() []struct { In1 *http.Request }
RoundTripCalls gets all the calls that were made to RoundTrip. Check the length with:
len(mockedRoundTripper.RoundTripCalls())