Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ByteData ¶
type ByteData []byte
ByteData implements the HTTPRequestBody and HTTPResponseBody for plain bytestrings.
func (ByteData) AssertResponseBody ¶
AssertResponseBody implements the HTTPResponseBody interface.
type FixtureFile ¶
type FixtureFile string
FixtureFile implements HTTPResponseBody by locating the expected plain-text response body in the given file.
func (FixtureFile) AssertResponseBody ¶
AssertResponseBody implements the HTTPResponseBody interface.
type HTTPRequest ¶
type HTTPRequest struct { // request properties Method string Path string Header map[string]string Body HTTPRequestBody // response properties ExpectStatus int ExpectBody HTTPResponseBody ExpectHeader map[string]string }
HTTPRequest is a HTTP request that gets executed by a unit test.
func (HTTPRequest) Check ¶
func (r HTTPRequest) Check(t *testing.T, handler http.Handler) (resp *http.Response, responseBody []byte)
Check performs the HTTP request described by this HTTPRequest against the given http.Handler and compares the response with the expectations in the HTTPRequest.
The HTTP response is returned, along with the response body. (resp.Body is already exhausted when the function returns.) This is useful for tests that want to do further checks on `resp` or want to use data from the response.
type HTTPRequestBody ¶
HTTPRequestBody is the type of field HTTPRequest.RequestBody. It is implemented by StringData and JSONObject.
type HTTPResponseBody ¶
type HTTPResponseBody interface { // Checks that the given actual response body is equal to this expected value. // `request` contains a user-readable representation of the original request, // for use in error messages. // // Returns whether the assertion was successful. AssertResponseBody(t *testing.T, requestInfo string, responseBody []byte) bool }
HTTPResponseBody is the type of field HTTPRequest.ExpectBody. It is implemented by StringData and JSONObject.
type JSONFixtureFile ¶
type JSONFixtureFile string
JSONFixtureFile implements HTTPResponseBody by locating the expected JSON response body in the given file.
func (JSONFixtureFile) AssertResponseBody ¶
func (f JSONFixtureFile) AssertResponseBody(t *testing.T, requestInfo string, responseBody []byte) bool
AssertResponseBody implements the HTTPResponseBody interface.
type JSONObject ¶
JSONObject implements HTTPRequestBody and HTTPResponseBody for JSON objects.
func (JSONObject) AssertResponseBody ¶
AssertResponseBody implements the HTTPResponseBody interface.
func (JSONObject) GetRequestBody ¶
func (o JSONObject) GetRequestBody() (io.Reader, error)
GetRequestBody implements the HTTPRequestBody interface.
type StringData ¶
type StringData string
StringData implements HTTPRequestBody and HTTPResponseBody for plain strings.
func (StringData) AssertResponseBody ¶
AssertResponseBody implements the HTTPResponseBody interface.
func (StringData) GetRequestBody ¶
func (s StringData) GetRequestBody() (io.Reader, error)
GetRequestBody implements the HTTPRequestBody interface.