Documentation ¶
Overview ¶
Package reqtest provides utilities for testing requests and responses.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHandler ¶
NewHandler creates a handler from an endpoint group for testing.
func NewRequestJSON ¶
NewRequestJSON wraps around httptest.NewRequest to return a new incoming server Request containing a JSON encoded request body. NewRequestJSON panics on error for ease of use in testing, where a panic is acceptable.
Types ¶
type ResponseRecord ¶
type ResponseRecord struct { StatusCode int Header http.Header Body []byte // contains filtered or unexported fields }
ResponseRecord contains the status code, header, and body of the recorded response. More fields may be populated in the future, so callers should not DeepEqual the result in tests. Use the provided assertion methods instead.
func (*ResponseRecord) AssertBodyContains ¶
func (r *ResponseRecord) AssertBodyContains(v string)
AssertBodyContains marks the test as failed if the response body does not contain the provided substring.
func (*ResponseRecord) AssertHeaderContains ¶
func (r *ResponseRecord) AssertHeaderContains(field string, v string)
AssertHeaderContains marks the test as failed if the response header field does not contain the provided substring.
func (*ResponseRecord) AssertStatusCode ¶
func (r *ResponseRecord) AssertStatusCode(v int)
AssertStatusCode marks the test as failed if the response status code does not match the expected value.