Documentation ¶
Index ¶
- func AnyError(errs ...error) error
- type HttpCall
- func (hc *HttpCall) AssertNoRequest() error
- func (hc *HttpCall) AssertNoResponse() error
- func (hc *HttpCall) AssertRequest() error
- func (hc *HttpCall) Call() Step
- func (hc *HttpCall) EnsureResponse() error
- func (hc *HttpCall) NewRequest(method, urlStr string, body io.Reader) Step
- func (hc *HttpCall) ReceiveBody() error
- func (hc *HttpCall) RequestHeader(key, value string) Step
- func (hc *HttpCall) Reset() error
- func (hc *HttpCall) ResponseBodyContains(value string) Step
- func (hc *HttpCall) ResponseBodyEquals(value string) Step
- func (hc *HttpCall) ResponseBodyJSONMatchesStruct(expected interface{}) Step
- func (hc *HttpCall) ResponseBodyJSONSchema(schema string) Step
- func (hc *HttpCall) ResponseBodyMatches(pattern *regexp.Regexp) Step
- func (hc *HttpCall) ResponseHeaderContains(key, value string) Step
- func (hc *HttpCall) ResponseHeaderEquals(key, value string) Step
- func (hc *HttpCall) ResponseHeaderExists(key string) Step
- func (hc *HttpCall) ResponseHeaderNotExists(key string) Step
- func (hc *HttpCall) ResponseStatusEquals(status int) Step
- type NamedStep
- type Step
- type StepFunc
- type Steps
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HttpCall ¶
type HttpCall struct { // The client used to perform the request. Client *http.Client // The request to be made. Request *http.Request // The response. Response *http.Response // The body which once received can be repeatedly reused. ResponseBody []byte }
HttpCall captures all the state relating to a single HTTP call. It may be used multiple times. An HttpCall can only be used by a single go-routine at a time.
func NewHttpCall ¶
NewHttpCall creates a new HttpCall. If client is nil, a new http.Client is used.
func (*HttpCall) AssertNoRequest ¶
AssertNoRequest returns nil iff hc.Request is nil.
func (*HttpCall) AssertNoResponse ¶
AssertNoResponse returns nil iff hc.Response is nil.
func (*HttpCall) AssertRequest ¶
AssertRequest returns nil iff hc.Request is non-nil.
func (*HttpCall) Call ¶
Call is a Step that when executed performs the HTTP Request Call. This is not normally necessary: all steps that require a Response will perform the HTTP Request when necessary. However, in some tests, you may not care about inspecting the HTTP Response but nevertheless wish the HTTP Request to be made.
func (*HttpCall) EnsureResponse ¶
EnsureResponse is idempotent. If there is already a response then it will return nil. Otherwise if there is no Request then it will return non-nil. Otherwise it will use hc.Client.Do to perform the request, set hc.Response, and return any error that occurs.
Always use this in any step where you want to inspect the hc.Response.
func (*HttpCall) NewRequest ¶
NewRequest is a Step that when executed will create a new request using the given parameters. The step will automatically call hc.Reset to tidy up any previous use of hc, and thus prepare hc for the new request.
func (*HttpCall) ReceiveBody ¶
ReceiveBody is idempotent. It will ensure there is a response using hc.EnsureResponse. If there is already a non-nil hc.ResponseBody then it will return nil. Otherwise it will receive the Response.Body, store it in hc.ResponseBody, and return any error that occurs.
Always use this in any step where you want to inspect the hc.ResponseBody.
func (*HttpCall) RequestHeader ¶
RequestHeader is a Step that when executed will set the given key and value as a header on the HTTP Request. This can only be done after hc.Request has been created (with NewRequest), and before hc.Response has been created.
func (*HttpCall) Reset ¶
Reset is idempotent. You should ensure this is called at the end of life for each HttpCall. It drains Response bodies if necessary, and cleans up resources.
func (*HttpCall) ResponseBodyContains ¶
ResponseBodyContains is a Step that when executed ensures there is a non-nil hc.ResponseBody and errors unless the hc.ResponseBody contains the value parameter using strings.Contains.
func (*HttpCall) ResponseBodyEquals ¶
ResponseBodyEquals is a Step that when executed ensures there is a non-nil hc.ResponseBody and errors unless the hc.ResponseBody equals the value parameter. Note this is an exact match.
func (*HttpCall) ResponseBodyJSONMatchesStruct ¶
ResponseBodyJSONMatchesStruct is a Step that when executed ensures there is a non-nil hc.ResponseBody, parses it as JSON (via encoding/json) based on the type of the expected structure and errors unless it is equal to the expected value, as validated by the pretty package. The error will contain a structured diff output with a plus/"+" marking the values that were expected and a minus/"-" marking the values that were actually present.
func (*HttpCall) ResponseBodyJSONSchema ¶
ResponseBodyJSONSchema is a Step that when executed ensures there is a non-nil hc.ResponseBody and errors unless the hc.ResponseBody can be validated against the schema parameter using gojsonschema.
func (*HttpCall) ResponseBodyMatches ¶
ResponseBodyMatches is a Step that when executed ensures there is a non-nil hc.ResponseBody and errors unless the hc.ResponseBody matches the regular expression parameter.
func (*HttpCall) ResponseHeaderContains ¶
ResponseHeaderContains is a Step that when executed ensures there is a non-nil hc.Response and errors unless the hc.Response.Header.Get(key) contains the value parameter using strings.Contains.
func (*HttpCall) ResponseHeaderEquals ¶
ResponseHeaderEquals is a Step that when executed ensures there is a non-nil hc.Response and errors unless the hc.Response.Header.Get(key) equals the value parameter. Note this is an exact match.
func (*HttpCall) ResponseHeaderExists ¶
ResponseHeaderExists is a Step that when executed ensures there is a non-nil hc.Response and errors unless hc.Response.Header[key] exists. It says nothing about the value of the header.
func (*HttpCall) ResponseHeaderNotExists ¶
ResponseHeaderNotExists is a Step that when executed ensures there is a non-nil hc.Response and errors unless hc.Response.Header[key] does not exist.
func (*HttpCall) ResponseStatusEquals ¶
ResponseStatusEquals is a Step that when executed ensures there is a non-nil hc.Response and errors unless the hc.Response.StatusCode equals the status parameter.
type NamedStep ¶
type NamedStep struct { StepFunc // contains filtered or unexported fields }
NamedStep extends StepFunc by adding a name, which is mainly of use when formatting a Step.
func NewNamedStep ¶
NewNamedStep creates a NamedStep with the given name and Step function.
type StepFunc ¶
type StepFunc func() error
StepFunc is the basic type of a Step: a function that takes no arguments and returns an error.
type Steps ¶
type Steps []Step
If we can have a single Step, then we can have a slice of Steps representing the order of Steps in a larger unit.
func (Steps) Test ¶
Test runs the steps in order and returns either all the steps, or all the steps that did not error, plus the step that errored. Thus the results are always a prefix of the Steps. t can be nil. If t is not nil and an error occurs, then t.Fatal will be called. If an error occurs, it will be returned.