Documentation ¶
Index ¶
- type ActionResponse
- type Client
- type Delay
- type Expectation
- type ExpectationOption
- func ThenAtLeastCalls(times int) ExpectationOption
- func ThenAtMostCalls(times int) ExpectationOption
- func ThenResponseDelay(delay time.Duration) ExpectationOption
- func ThenResponseJSON(body string) ExpectationOption
- func ThenResponseStatus(statusCode int) ExpectationOption
- func ThenResponseText(body string) ExpectationOption
- func WhenRequestAuth(authToken string) ExpectationOption
- func WhenRequestHeaders(headers map[string][]string) ExpectationOption
- func WhenRequestMethod(method string) ExpectationOption
- func WhenRequestPath(path string) ExpectationOption
- func WhenRequestQueryStringParameters(qsp map[string][]string) ExpectationOption
- func WhenTimes(times int) ExpectationOption
- type RequestMatcher
- type ResponseBody
- type Times
- type VerificationSequence
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionResponse ¶
type ActionResponse struct { Headers map[string][]string `json:"headers,omitempty"` StatusCode int `json:"statusCode,omitempty"` Body *ResponseBody `json:"body,omitempty"` Delay *Delay `json:"delay,omitempty"` }
ActionResponse defines what actions to take when a request is matched e.g. response, delay, forward etc.
type Client ¶
Client wraps the testing context used for all interactions with MockServer
func (*Client) AddExpectation ¶
func (c *Client) AddExpectation(exp *Expectation)
AddExpectation adds an expectation based on a request matcher to MockServer
func (*Client) AddVerification ¶
func (c *Client) AddVerification(exp *Expectation)
AddVerification adds a verification of requests to MockServer
func (*Client) AddVerificationSequence ¶
func (c *Client) AddVerificationSequence(exps ...*Expectation)
AddVerificationSequence adds a verification of a specific sequence of requests to MockServer
type Expectation ¶
type Expectation struct { Request *RequestMatcher `json:"httpRequest"` Response *ActionResponse `json:"httpResponse,omitempty"` Times *Times `json:"times,omitempty"` }
Expectation defines the complete request/response interaction for a given scenario
func CreateExpectation ¶
func CreateExpectation(opts ...ExpectationOption) *Expectation
CreateExpectation converts a number of expectation parts (options) into a single Expectation
func CreateVerification ¶
func CreateVerification(opts ...ExpectationOption) *Expectation
CreateVerification converts a number of expectation parts (options) into a single Expectation
type ExpectationOption ¶
type ExpectationOption func(e *Expectation) *Expectation
ExpectationOption enables building expectations in many parts
func ThenAtLeastCalls ¶
func ThenAtLeastCalls(times int) ExpectationOption
ThenAtLeastCalls creates a verification that a matching call was received at least x times by MockServer
func ThenAtMostCalls ¶
func ThenAtMostCalls(times int) ExpectationOption
ThenAtMostCalls creates a verification that a matching call was received at most x times by MockServer
func ThenResponseDelay ¶
func ThenResponseDelay(delay time.Duration) ExpectationOption
ThenResponseDelay creates an action that delays returning an HTTP response when a request is matched
func ThenResponseJSON ¶
func ThenResponseJSON(body string) ExpectationOption
ThenResponseJSON creates an action that returns an HTTP body as JSON when a request is matched
func ThenResponseStatus ¶
func ThenResponseStatus(statusCode int) ExpectationOption
ThenResponseStatus creates an action that returns an HTTP status code when a request is matched
func ThenResponseText ¶
func ThenResponseText(body string) ExpectationOption
ThenResponseText creates an action that returns an HTTP body as text when a request is matched
func WhenRequestAuth ¶
func WhenRequestAuth(authToken string) ExpectationOption
WhenRequestAuth creates an expectation based on a required Authorization request header
func WhenRequestHeaders ¶
func WhenRequestHeaders(headers map[string][]string) ExpectationOption
WhenRequestHeaders creates an expectation based on required request headers
func WhenRequestMethod ¶
func WhenRequestMethod(method string) ExpectationOption
WhenRequestMethod creates an expectation based on an HTTP method
func WhenRequestPath ¶
func WhenRequestPath(path string) ExpectationOption
WhenRequestPath creates an expectation based on a path
func WhenRequestQueryStringParameters ¶
func WhenRequestQueryStringParameters(qsp map[string][]string) ExpectationOption
WhenRequestQueryStringParameters creates an expectation based on required query string parameters
func WhenTimes ¶
func WhenTimes(times int) ExpectationOption
WhenTimes creates an expectation bounded by a limited number of calls
type RequestMatcher ¶
type RequestMatcher struct { Path string `json:"path,omitempty"` Method string `json:"method,omitempty"` Headers map[string][]string `json:"headers,omitempty"` QueryStringParameters map[string][]string `json:"queryStringParameters,omitempty"` }
RequestMatcher is used to match which requests the expectation will be applied to
type ResponseBody ¶
ResponseBody defines the request body the MockServer will return when serving a matched response
type Times ¶
type Times struct { AtLeast *int `json:"atLeast,omitempty"` // valid for verifications only AtMost *int `json:"atMost,omitempty"` // valid for verifications only RemainingTimes int `json:"remainingTimes,omitempty"` // valid for expectations only Unlimited *bool `json:"unlimited,omitempty"` // valid for expectations only }
Times defines how many times the MockServer will serve a given request in expectation mode whilst in verification mode defines the expected number of calls
type VerificationSequence ¶
type VerificationSequence struct {
Requests []*RequestMatcher `json:"httpRequests"`
}
VerificationSequence defines a specific ordered sequence of requests to MockServer