Documentation ¶
Index ¶
- Variables
- type Assert
- func (a *Assert) Body(expected string, res *ResponseRecorder, msgContext ...interface{})
- func (a *Assert) Cookie(res *ResponseRecorder, name string, msgContext ...interface{}) *http.Cookie
- func (a *Assert) Header(expected string, res *ResponseRecorder, fieldName string, ...)
- func (a *Assert) JSON(v interface{}, res *ResponseRecorder, msgContext ...interface{})
- func (a *Assert) Status(expected response.HTTPStatus, res *ResponseRecorder, msgContext ...interface{})
- type Recorder
- func (r *Recorder) NewRequest(method, path string, v interface{}, options ...RequestOption) *http.Request
- func (r *Recorder) TestDelete(path string, options ...RequestOption) *ResponseRecorder
- func (r *Recorder) TestGet(path string, options ...RequestOption) *ResponseRecorder
- func (r *Recorder) TestPost(path string, v interface{}, options ...RequestOption) *ResponseRecorder
- func (r *Recorder) TestPut(path string, v interface{}, options ...RequestOption) *ResponseRecorder
- func (r *Recorder) TestRequest(req *http.Request) *ResponseRecorder
- type RequestFactory
- type RequestFactoryFunc
- type RequestOption
- type ResponseRecorder
- type Runner
Constants ¶
This section is empty.
Variables ¶
var DefaultRequestFactory = RequestFactoryFunc(http.NewRequest)
DefaultRequestFactory is a RequestFactory on top of http.NewRequest
Functions ¶
This section is empty.
Types ¶
type Assert ¶
Assert is a wrapper for github.com/yssk22/go/x/xtesting/assert.Assert and provides http specific assertions
func (*Assert) Body ¶
func (a *Assert) Body(expected string, res *ResponseRecorder, msgContext ...interface{})
Body asserts the body string
func (*Assert) Cookie ¶
func (a *Assert) Cookie(res *ResponseRecorder, name string, msgContext ...interface{}) *http.Cookie
Cookie asserts the cookie name and extract it as *http.Cookie
func (*Assert) Header ¶
func (a *Assert) Header(expected string, res *ResponseRecorder, fieldName string, msgContext ...interface{})
Header asserts the header value
func (*Assert) JSON ¶
func (a *Assert) JSON(v interface{}, res *ResponseRecorder, msgContext ...interface{})
JSON asserts the body string as as json and returns the result as interface{}
func (*Assert) Status ¶
func (a *Assert) Status(expected response.HTTPStatus, res *ResponseRecorder, msgContext ...interface{})
Status asserts the http status code
type Recorder ¶
Recorder is a test recorder.
func NewRecorder ¶
NewRecorder returns a new *Recorder
func NewRecorderWithFactory ¶
func NewRecorderWithFactory(handler http.Handler, factory RequestFactory) *Recorder
NewRecorderWithFactory returns a new *Recorder with the custom factory configuration
func (*Recorder) NewRequest ¶
func (r *Recorder) NewRequest(method, path string, v interface{}, options ...RequestOption) *http.Request
NewRequest returns http.Request with request body given by `v`
func (*Recorder) TestDelete ¶
func (r *Recorder) TestDelete(path string, options ...RequestOption) *ResponseRecorder
TestDelete make a test DELETE request to the router and returns the response as *http.ResponseRecorder
func (*Recorder) TestGet ¶
func (r *Recorder) TestGet(path string, options ...RequestOption) *ResponseRecorder
TestGet make a test GET request to the router and returns the response as *http.ResponseRecorder
func (*Recorder) TestPost ¶
func (r *Recorder) TestPost(path string, v interface{}, options ...RequestOption) *ResponseRecorder
TestPost make a test POST request to the router and returns the response as *http.ResponseRecorder
func (*Recorder) TestPut ¶
func (r *Recorder) TestPut(path string, v interface{}, options ...RequestOption) *ResponseRecorder
TestPut make a test PUT request to the router and returns the response as *http.ResponseRecorder
func (*Recorder) TestRequest ¶
func (r *Recorder) TestRequest(req *http.Request) *ResponseRecorder
TestRequest make a test request to the router and returns the response as *http.ResponseRecorder
type RequestFactory ¶
RequestFactory is an interface to create a new request.
type RequestFactoryFunc ¶
RequestFactoryFunc is a wrapper to NewRequest function to be RequestFactory
func (RequestFactoryFunc) NewRequest ¶
func (f RequestFactoryFunc) NewRequest(method string, path string, body io.Reader) (*http.Request, error)
NewRequest implements RequestFactory#NewRequest
type RequestOption ¶
RequestOption is a option function to configure a request
func Header ¶
func Header(key string, value string) RequestOption
Header set the request header for Test functions
type ResponseRecorder ¶
type ResponseRecorder struct { *httptest.ResponseRecorder Request *http.Request }
func (*ResponseRecorder) Dump ¶
func (r *ResponseRecorder) Dump() string
Dump returns the http trace dump