Documentation ¶
Overview ¶
Originally from https://github.com/ant0ine/go-json-rest/master/test/util.go Utility functions to help writing tests for a Go-Json-Rest app
Go comes with net/http/httptest to help writing test for an http server. When this http server implements a JSON REST API, some basic checks end up to be always the same. This test package tries to save some typing by providing helpers for this particular use case.
Index ¶
- func BodyIs(t *testing.T, r *httptest.ResponseRecorder, expectedBody string)
- func CodeIs(t *testing.T, r *httptest.ResponseRecorder, expectedCode int)
- func ContentEncodingIsGzip(t *testing.T, r *httptest.ResponseRecorder)
- func ContentTypeIsJson(t *testing.T, r *httptest.ResponseRecorder)
- func DecodeJsonPayload(r *httptest.ResponseRecorder, v interface{}) error
- func HeaderIs(t *testing.T, r *httptest.ResponseRecorder, headerKey, expectedValue string)
- func MakeSimpleRequest(method string, urlStr string, payload interface{}) *http.Request
- type Recorded
- func (self *Recorded) BodyIs(expectedBody string)
- func (self *Recorded) CodeIs(expectedCode int)
- func (self *Recorded) ContentEncodingIsGzip()
- func (self *Recorded) ContentTypeIsJson()
- func (self *Recorded) DecodeJsonPayload(v interface{}) error
- func (self *Recorded) HeaderIs(headerKey, expectedValue string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContentEncodingIsGzip ¶
func ContentEncodingIsGzip(t *testing.T, r *httptest.ResponseRecorder)
func ContentTypeIsJson ¶
func ContentTypeIsJson(t *testing.T, r *httptest.ResponseRecorder)
func DecodeJsonPayload ¶
func DecodeJsonPayload(r *httptest.ResponseRecorder, v interface{}) error
Types ¶
type Recorded ¶
type Recorded struct { T *testing.T Recorder *httptest.ResponseRecorder }
func RunRequest ¶
func (*Recorded) ContentEncodingIsGzip ¶
func (self *Recorded) ContentEncodingIsGzip()
func (*Recorded) ContentTypeIsJson ¶
func (self *Recorded) ContentTypeIsJson()
func (*Recorded) DecodeJsonPayload ¶
Click to show internal directories.
Click to hide internal directories.