Documentation ¶
Overview ¶
Package fipple is a lightweight utility that makes it easy to write integration tests for REST APIs.
Index ¶
- type Recorder
- func (r *Recorder) Close()
- func (r *Recorder) Delete(path string) *Response
- func (r *Recorder) Do(req *http.Request) *Response
- func (r *Recorder) Get(path string) *Response
- func (r *Recorder) GetCookies() []*http.Cookie
- func (r *Recorder) NewJSONRequest(method string, path string, data interface{}) *http.Request
- func (r *Recorder) NewMultipartRequest(method string, path string, fields map[string]string, ...) *http.Request
- func (r *Recorder) NewRequest(method string, path string) *http.Request
- func (r *Recorder) NewRequestWithData(method string, path string, data map[string]string) *http.Request
- func (r *Recorder) Post(path string, data map[string]string) *Response
- func (r *Recorder) Put(path string, data map[string]string) *Response
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Recorder ¶
type Recorder struct { // Colorize is used to determine whether or not to colorize the errors when // printing to the console using t.Error. The default is true. Colorize bool // contains filtered or unexported fields }
Recorder can be used to send http requests and record the responses.
func NewRecorder ¶
NewRecorder returns a recorder that sends requests through the given handler. The recorder will report any errors using t.Error or t.Fatal.
func NewURLRecorder ¶
NewURLRecorder creates a new recorder with the given baseURL. The recorder will report any errors using t.Error or t.Fatal.
func (*Recorder) Close ¶
func (r *Recorder) Close()
Close closes the recorder. You must call Close when you are done using a recorder.
func (*Recorder) Delete ¶
Delete sends a DELETE request to the given path and records the results into a fipple.Response. path will be appended to the baseURL for the recorder to create the full URL. You can run methods on the response to check the results. Any errors that occur will be passed to t.Fatal
func (*Recorder) Do ¶
Do sends req and records the results into a fipple.Response. Note that because an http.Request should have already been created with a full, valid url, the baseURL of the Recorder will not be prepended to the url for req. You can run methods on the response to check the results. Any errors that occur will be passed to t.Fatal
func (*Recorder) Get ¶
Get sends a GET request to the given path and records the results into a fipple.Response. path will be appended to the baseURL for the recorder to create the full URL. You can run methods on the response to check the results. Any errors that occur will be passed to t.Fatal
func (*Recorder) GetCookies ¶
GetCookies returns the raw cookies that have been set as a result of any requests recorded by a Recorder. Any errors that occur will be passed to t.Fatal
func (*Recorder) NewJSONRequest ¶
NewJSONRequest creates and returns a JSON request with the given method and path (which is appended to the baseURL. data can be any data structure but cannot include functions or recursiveness. NewJSONRequest will convert data into json using json.Marshall. The Content-Type header will automatically be added. Any errors tha occur will be passed to t.Fatal.
func (*Recorder) NewMultipartRequest ¶
func (r *Recorder) NewMultipartRequest(method string, path string, fields map[string]string, files map[string]*os.File) *http.Request
NewMultipartRequest can be used to easily create (and later send) a request with form data and/or files (encoded as multipart/form-data). fields is a key-value map of basic string fields for the form data, and files is a map of key to *os.File. The Content-Type header will automatically be added. Any errors tha occur will be passed to t.Fatal.
func (*Recorder) NewRequest ¶
NewRequest creates a new request object with the given http method and path. The path will be appended to the baseURL for the recorder to create the full URL. You are free to add additional parameters or headers to the request before sending it. Any errors that occur will be passed to t.Fatal.
func (*Recorder) NewRequestWithData ¶
func (r *Recorder) NewRequestWithData(method string, path string, data map[string]string) *http.Request
NewRequestWithData can be used to easily send a request with form data (encoded as application/x-www-form-urlencoded). The path will be appended to the baseURL for the recorder to create the full URL. The Content-Type header will automatically be added. Any errors tha occur will be passed to t.Fatal.
func (*Recorder) Post ¶
Post sends a POST request to the given path using the given data as post parameters and records the results into a fipple.Response. path will be appended to the baseURL for the recorder to create the full URL. You can run methods on the response to check the results. Any errors that occur will be passed to t.Fatal
func (*Recorder) Put ¶
Put sends a PUT request to the given path using the given data as parameters and records the results into a fipple.Response. path will be appended to the baseURL for the recorder to create the full URL. You can run methods on the response to check the results. Any errors that occur will be passed to t.Fatal
type Response ¶
Response represents the response from an http request and has methods to make testing easier.
func (*Response) ExpectBodyContains ¶
ExpectBodyContains causes a test error if the response body does not contain the given string.
func (*Response) ExpectCode ¶
ExpectCode causes a test error if response code != the given code
func (*Response) ExpectOk ¶
func (r *Response) ExpectOk()
ExpectOk causes a test error if response code != 200
func (*Response) PrintFailure ¶
func (r *Response) PrintFailure()
PrintFailure prints some information about the response via t.Errorf. This includes the method, the url, and the response body. If the Content-Type of the response is application/json, PrintFailure will automatically indent it.
func (*Response) PrintFailureOnce ¶
func (r *Response) PrintFailureOnce()
PrintFailureOnce is like PrintFailure but only prints out the information once per response, regardless of how many times it is called.