Documentation
¶
Index ¶
- func ExpectedCookie(name string) *expectedCookie
- type APITest
- type Assert
- type Intercept
- type Observe
- type Request
- func (r *Request) BasicAuth(auth string) *Request
- func (r *Request) Body(b string) *Request
- func (r *Request) Cookies(c ...*expectedCookie) *Request
- func (r *Request) Delete(url string) *Request
- func (r *Request) Expect(t *testing.T) *Response
- func (r *Request) Get(url string) *Request
- func (r *Request) Headers(h map[string]string) *Request
- func (r *Request) Intercept(interceptor Intercept) *Request
- func (r *Request) Method(method string) *Request
- func (r *Request) Patch(url string) *Request
- func (r *Request) Post(url string) *Request
- func (r *Request) Put(url string) *Request
- func (r *Request) Query(q map[string]string) *Request
- func (r *Request) QueryCollection(q map[string][]string) *Request
- func (r *Request) URL(url string) *Request
- type Response
- func (r *Response) Assert(fn func(*http.Response, *http.Request) error) *Response
- func (r *Response) Body(b string) *Response
- func (r *Response) CookieNotPresent(cookieName string) *Response
- func (r *Response) CookiePresent(cookieName string) *Response
- func (r *Response) Cookies(cookies ...*expectedCookie) *Response
- func (r *Response) End()
- func (r *Response) Headers(headers map[string]string) *Response
- func (r *Response) JSONPath(expression string, assert func(interface{})) *Response
- func (r *Response) Status(s int) *Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpectedCookie ¶ added in v0.0.11
func ExpectedCookie(name string) *expectedCookie
Types ¶
type APITest ¶
type APITest struct {
// contains filtered or unexported fields
}
APITest is the top level struct holding the test spec
func (*APITest) BuildRequest ¶
type Assert ¶
Assert is a user defined custom assertion function
var IsClientError Assert = func(response *http.Response, request *http.Request) error { if response.StatusCode >= 400 && response.StatusCode < 500 { return nil } return errors.New("not a client error. Status code=" + strconv.Itoa(response.StatusCode)) }
IsClientError is a convenience function to assert on a range of client error status codes
var IsServerError Assert = func(response *http.Response, request *http.Request) error { if response.StatusCode >= 500 { return nil } return errors.New("not a server error. Status code=" + strconv.Itoa(response.StatusCode)) }
IsServerError is a convenience function to assert on a range of server error status codes
var IsSuccess Assert = func(response *http.Response, request *http.Request) error { if response.StatusCode >= 200 && response.StatusCode < 400 { return nil } return errors.New("not a client error. Status code=" + strconv.Itoa(response.StatusCode)) }
IsSuccess is a convenience function to assert on a range of happy path status codes
type Intercept ¶
Intercept will be called before the request is made. Updates to the request will be reflected in the test
type Observe ¶
Observe will be called by with the request and response on completion
var DumpHttp Observe = func(res *http.Response, req *http.Request) { requestDump, err := httputil.DumpRequest(req, true) if err == nil { fmt.Println("--> http request dump\n\n" + string(requestDump)) } responseDump, err := httputil.DumpResponse(res, true) if err == nil { fmt.Println("<-- http response dump:\n\n" + string(responseDump)) } }
DumpHttp logs the http wire representation of the request and response
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is the user defined request that will be invoked on the handler under test
func (*Request) BasicAuth ¶
BasicAuth is a builder method to sets basic auth on the request. The credentials should be provided delimited by a colon, e.g. "username:password"
func (*Request) Delete ¶
Delete is a convenience method for setting the request as http.MethodDelete
func (*Request) Expect ¶
Expect marks the request spec as complete and following code will define the expected response
func (*Request) Query ¶
Query is a builder method to set the request query parameters. This can be used in combination with request.QueryCollection
func (*Request) QueryCollection ¶
QueryCollection is a builder method to set the request query parameters This can be used in combination with request.Query
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is the user defined expected response from the application under test
func (*Response) Assert ¶
Assert allows the consumer to provide a user defined function containing their own custom assertions
func (*Response) CookieNotPresent ¶
CookieNotPresent is used to assert that a cookie is not present in the response
func (*Response) CookiePresent ¶
CookiePresent is used to assert that a cookie is present in the response, regardless of its value
func (*Response) JSONPath ¶
JSONPath provides support for jsonpath expectations as defined by https://goessner.net/articles/JsonPath/