Documentation ¶
Overview ¶
Package http includes useful extensions to the net/http/httptest package.
Index ¶
- type ResponseRecorder
- func (rr *ResponseRecorder) AssertBody(want string)
- func (rr *ResponseRecorder) AssertBodyJSON(want interface{})
- func (rr *ResponseRecorder) AssertHeader(name string, want string)
- func (rr *ResponseRecorder) AssertNoBody()
- func (rr *ResponseRecorder) AssertStatus(want int)
- func (rr *ResponseRecorder) GetBody() []byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ResponseRecorder ¶
type ResponseRecorder struct { *httptest.ResponseRecorder // embed the stdlib ResponseRecorder for API parity // contains filtered or unexported fields }
ResponseRecorder is an augmented version of net.http.httptest.ResponseRecorder with the ability to make various assertions concerning the HTTP response that was observed.
func NewResponseRecorder ¶
func NewResponseRecorder(t *testing.T) *ResponseRecorder
Build a new ResponseRecorder that extends the net/http/httptest one by attaching some functions making it simple to assert some facts about the response or record an error if those assertions fail.
Because the recording is parameterized by a single testing.T this should not be resude between test cases.
func (*ResponseRecorder) AssertBody ¶
func (rr *ResponseRecorder) AssertBody(want string)
Compares the wanted body against what was sent in the response and records an error if they don't match.
func (*ResponseRecorder) AssertBodyJSON ¶
func (rr *ResponseRecorder) AssertBodyJSON(want interface{})
Convenience method that renders an object as json and then compares that to the body sent in the response. If they don't match a test error will be recorded.
func (*ResponseRecorder) AssertHeader ¶
func (rr *ResponseRecorder) AssertHeader(name string, want string)
Fetches the header name's value, compares to want and records an error if they don't match.
func (*ResponseRecorder) AssertNoBody ¶
func (rr *ResponseRecorder) AssertNoBody()
If the response had any body content this will record a test error.
func (*ResponseRecorder) AssertStatus ¶
func (rr *ResponseRecorder) AssertStatus(want int)
If the response did not have the indicated status this records a test error.
func (*ResponseRecorder) GetBody ¶
func (rr *ResponseRecorder) GetBody() []byte
Convenience method that returns the contents of the body.