Documentation ¶
Overview ¶
Package testutils provides utilities for testing purposes
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExpectedRequest ¶
An ExpectedRequest represents the expected request that will be matched against the incoming http request
type Response ¶
A Response represents the response to return when the incoming request matches the ExpectedRequest
type TestClientServer ¶
type TestClientServer struct {
RequestMatcher TestRequestMatcher
}
TestClientServer represents a mock server configured with a matcher and a working client that is able to send requests to the server
func (*TestClientServer) TestClientServer ¶
func (t *TestClientServer) TestClientServer() (*http.Client, *httptest.Server)
TestClientServer creates a client and a server that the user can then use in unit tests. The server returned will serve a response only if the incoming request matches the configured expected request.
type TestRequestMatcher ¶
type TestRequestMatcher struct { ExpectedRequest ExpectedRequest Response Response }
A TestRequestMatcher represents the expected behaviour of the mock server
func NewRequestMatcher ¶
func NewRequestMatcher(expectedHttpMethod, expectedPath string, expectedPayload interface{}, responseStatusCode int, response interface{}) TestRequestMatcher
NewRequestMatcher constructs a TestRequestMatcher used to match an http.Request with the expected configured request and returns the configured response in JSON and status code
func NewRequestMatcherWithOptions ¶
func NewRequestMatcherWithOptions(expectedHttpMethod, expectedPath string, expectedPayload interface{}, responseStatusCode int, response interface{}, responseRawContent bool) TestRequestMatcher
NewRequestMatcher constructs a TestRequestMatcher used to match an http.Request with the expected configured request and return the configured response (either in JSON or RAW depending on the value provided for responseRawContent) and status code