Documentation ¶
Overview ¶
Package github.comeid/omeid/httptest extends net/http/httptest with useful methods for HTTP testing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ResponseRecoder ¶
type ResponseRecoder struct {
*httptest.ResponseRecorder
}
ResponseRecorder is an extension of httptest.ResponseRecoder which implementation of http.ResponseWriter that records its mutations for later inspection in tests.
func NewRecorder ¶
func NewRecorder() *ResponseRecoder
NewRecorder returns an initialized ResponseRecorder, it's compatiable with the official httptest.ResponseRecoder by embedding it.
func (*ResponseRecoder) ExpectBytes ¶
func (r *ResponseRecoder) ExpectBytes(expect []byte, strict bool) ([]byte, bool)
ExpectBytes check the response body against the provided []byte, if strict is set to false, It will ignore a possible trialing '\n' in response body.
func (*ResponseRecoder) ExpectContentType ¶
func (r *ResponseRecoder) ExpectContentType(expect string) (string, bool)
Checks if the Response has the expected content type, returns the content type And if it is matching.
func (*ResponseRecoder) ExpectJSON ¶
func (r *ResponseRecoder) ExpectJSON(model, expect interface{}) ([]byte, bool)
ExpectJSON checks if decoding the body to `model` will match the `expect` object. Providing mismatching Model and Expect will result into a fatal error.
func (*ResponseRecoder) ExpectStatus ¶
func (r *ResponseRecoder) ExpectStatus(expect int) (int, bool)
CheckCode checks returns the response status code and if it matches the expected status code. This is mostly provided for consistency with other method and http's package refering to Status Code as Status, you can directly acess the Code as `ResponseRecoder.Code` if you may.