Documentation ¶
Index ¶
- type Client
- func (c *Client) Delete(t TestingT, urlStr string, expectedStatuses ...int) *Response
- func (c *Client) Do(t TestingT, req *Request, expectedStatuses ...int) *Response
- func (c *Client) Get(t TestingT, urlStr string, expectedStatuses ...int) *Response
- func (c *Client) Head(t TestingT, urlStr string, expectedStatuses ...int) *Response
- func (c *Client) NewRequest(t TestingT, method string, urlStr string, body fmt.Stringer) *Request
- func (c *Client) Patch(t TestingT, urlStr string, body fmt.Stringer, expectedStatuses ...int) *Response
- func (c *Client) Post(t TestingT, urlStr string, body fmt.Stringer, expectedStatuses ...int) *Response
- func (c *Client) Put(t TestingT, urlStr string, body fmt.Stringer, expectedStatuses ...int) *Response
- type Request
- func (req *Request) AddCookies(c []http.Cookie) *Request
- func (req *Request) AddHeaders(h http.Header) *Request
- func (req *Request) EnableRecording(baseFileName string) *Request
- func (req *Request) SetBodyReader(r io.Reader) *Request
- func (req *Request) SetBodyString(s string) *Request
- func (req *Request) SetBodyStringer(s fmt.Stringer) *Request
- type Response
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Base url.URL HTTPClient *http.Client DefaultHeaders http.Header DefaultCookies []http.Cookie }
Client wraps base API URL with default headers and cookies. Base URL can contain scheme, user info, host, path prefix and default query parameters.
func (*Client) Do ¶
Do makes request and returns response. It also logs and records them and checks that response status code is equal to one of the provided. Request and response Body fields are filled, inner *http.(Request|Response).Body fields are replaced by stubs. In case of error it fails test.
func (*Client) NewRequest ¶
NewRequest creates new request with given method, URL and body. It adds URL's path and query parameters to client's base URL. It also adds default headers and cookies from client. In case of error if fails test.
func (*Client) Patch ¶
func (c *Client) Patch(t TestingT, urlStr string, body fmt.Stringer, expectedStatuses ...int) *Response
Patch makes PATCH request. See Do for more details.
type Request ¶
type Request struct { *http.Request Body []byte // filled by Client.Do Recorder recorders.Interface RequestWC io.WriteCloser ResponseWC io.WriteCloser }
Request represents HTTP request and recording parameters.
func (*Request) AddCookies ¶
AddCookies adds cookies to request.
func (*Request) AddHeaders ¶
AddHeaders adds headers to request.
func (*Request) EnableRecording ¶
EnableRecording enables recording of this request and following response to files with given base name. Recorder type is selected by extension: recorders.APIB for ".apib", recorders.Plain for any other.
func (*Request) SetBodyReader ¶
SetBodyReader sets request body with given reader. It also tries to set Content-Length header.
func (*Request) SetBodyString ¶
SetBodyString sets request body with given string. It also sets Content-Length header.
type TestingT ¶
type TestingT interface { // Log formats its arguments using default formatting, analogous to Println, and records the text in the error log. Log(args ...interface{}) // Logf formats its arguments according to the format, analogous to Printf, and records the text in the error log. Logf(format string, args ...interface{}) // Failed reports whether the function has failed. Failed() bool // Fail marks the function as having failed but continues execution. Fail() // Error is equivalent to Log followed by Fail. Error(args ...interface{}) // Errorf is equivalent to Logf followed by Fail. Errorf(format string, args ...interface{}) // FailNow marks the function as having failed and stops its execution. Execution will continue at the next test. // FailNow must be called from the goroutine running the test function, not from other goroutines created during the test. // Calling FailNow does not stop those other goroutines. FailNow() // Fatal is equivalent to Log followed by FailNow. Fatal(args ...interface{}) // Fatalf is equivalent to Logf followed by FailNow. Fatalf(format string, args ...interface{}) // Skipped reports whether the test was skipped. Skipped() bool // SkipNow marks the test as having been skipped and stops its execution. Execution will continue at the next test. See also FailNow. // SkipNow must be called from the goroutine running the test, not from other goroutines created during the test. // Calling SkipNow does not stop those other goroutines. SkipNow() // Skip is equivalent to Log followed by SkipNow. Skip(args ...interface{}) // Skipf is equivalent to Logf followed by SkipNow. Skipf(format string, args ...interface{}) }
TestingT is a copy of testing.TB interface without private methods. It can be used to hook other testing libraries, frameworks, and runners, such as gophers tool.
Directories ¶
Path | Synopsis |
---|---|
Package config contains configuration for various Gophers methods.
|
Package config contains configuration for various Gophers methods. |
examples
|
|
gophers/placehold
Package placehold contains Gophers examples for placehold.it to be used with gophers tool.
|
Package placehold contains Gophers examples for placehold.it to be used with gophers tool. |
testing/github
Package github contains Gophers examples for github.com to be used with go test tool.
|
Package github contains Gophers examples for github.com to be used with go test tool. |
testing/placehold
Package placehold contains Gophers examples for placehold.it to be used with gophers tool.
|
Package placehold contains Gophers examples for placehold.it to be used with gophers tool. |
exp
|
|
glua
Package glua provideds Lua bindigs for Gophers tool.
|
Package glua provideds Lua bindigs for Gophers tool. |
Package gophers implements gophers tool.
|
Package gophers implements gophers tool. |
cmd
Package cmd contains implementation of gophers tool commands.
|
Package cmd contains implementation of gophers tool commands. |
runner
Package runner implements test runner used by gophers tool.
|
Package runner implements test runner used by gophers tool. |
Package jsons allows sloppy work with JSON structures (objects and arrays).
|
Package jsons allows sloppy work with JSON structures (objects and arrays). |
Package recorders providers request/response recorders for Gophers tool.
|
Package recorders providers request/response recorders for Gophers tool. |
utils
|
|
taskpool
Package taskpool provides task pool with variable amount of worker goroutines.
|
Package taskpool provides task pool with variable amount of worker goroutines. |