Documentation ¶
Index ¶
- Variables
- func AddQueryParameters(baseURL string, queryParams map[string]string) string
- func BuildRequestObject(request Request) (*http.Request, error)
- func MakeRequest(req *http.Request) (*http.Response, error)
- type API
- type BodyMatcher
- type Client
- func (c *Client) API(request Request) (*Response, error)deprecated
- func (c *Client) AddMocks(_ []*Mock) error
- func (c *Client) MakeRequest(req *http.Request) (*http.Response, error)
- func (c *Client) Reset() error
- func (c *Client) Send(request Request) (*Response, error)
- func (c *Client) SendWithContext(ctx context.Context, request Request) (*Response, error)
- type Delay
- type MapStringSlice
- type Method
- type Mock
- type MockBuilder
- func (mb *MockBuilder) AddRequestBodyJSON(key string, body StringMatcher) *MockBuilder
- func (mb *MockBuilder) AddRequestHeader(name string, value StringMatcher) *MockBuilder
- func (mb *MockBuilder) AddRequestQueryParam(name string, value StringMatcher) *MockBuilder
- func (mb *MockBuilder) AddResponseHeader(name string, value string) *MockBuilder
- func (mb *MockBuilder) Mock() *Mock
- func (mb *MockBuilder) SetContextTimes(times uint) *MockBuilder
- func (mb *MockBuilder) SetRequestBodyString(body StringMatcher) *MockBuilder
- func (mb *MockBuilder) SetRequestHeaders(headers MultiMapMatcher) *MockBuilder
- func (mb *MockBuilder) SetRequestMethod(method StringMatcher) *MockBuilder
- func (mb *MockBuilder) SetRequestPath(path StringMatcher) *MockBuilder
- func (mb *MockBuilder) SetRequestQueryParams(queryParams MultiMapMatcher) *MockBuilder
- func (mb *MockBuilder) SetResponseBody(body string) *MockBuilder
- func (mb *MockBuilder) SetResponseDelay(min, max time.Duration) *MockBuilder
- func (mb *MockBuilder) SetResponseHeaders(headers MapStringSlice) *MockBuilder
- func (mb *MockBuilder) SetResponseStatus(status int) *MockBuilder
- type MockContext
- type MockRequest
- type MockResponse
- type MultiMapMatcher
- type Request
- type Response
- type RestError
- type StringMatcher
- func ShouldBeEmpty(value string) StringMatcher
- func ShouldContainSubstring(value string) StringMatcher
- func ShouldEndWith(value string) StringMatcher
- func ShouldEqual(value string) StringMatcher
- func ShouldEqualJSON(value string) StringMatcher
- func ShouldMatch(value string) StringMatcher
- func ShouldNotBeEmpty(value string) StringMatcher
- func ShouldNotContainSubstring(value string) StringMatcher
- func ShouldNotEndWith(value string) StringMatcher
- func ShouldNotEqual(value string) StringMatcher
- func ShouldNotMatch(value string) StringMatcher
- func ShouldNotResemble(value string) StringMatcher
- func ShouldNotStartWith(value string) StringMatcher
- func ShouldResemble(value string) StringMatcher
- func ShouldStartWith(value string) StringMatcher
- type StringMatcherSlice
- type StringSlice
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultClient = &Client{HTTPClient: &http.Client{}}
DefaultClient is used if no custom HTTP client is defined
Functions ¶
func AddQueryParameters ¶
AddQueryParameters adds query parameters to the URL.
func BuildRequestObject ¶
BuildRequestObject creates the HTTP request object.
Types ¶
type API ¶
type API struct {
URL string
}
type BodyMatcher ¶ added in v0.2.0
type BodyMatcher struct { BodyString *StringMatcher BodyJSON map[string]StringMatcher }
func (BodyMatcher) MarshalJSON ¶ added in v0.2.0
func (bm BodyMatcher) MarshalJSON() ([]byte, error)
type Client ¶
Client allows modification of client headers, redirect policy and other settings See https://golang.org/pkg/net/http
func (*Client) MakeRequest ¶
MakeRequest makes the API call.
type MapStringSlice ¶ added in v0.2.0
type MapStringSlice map[string]StringSlice
type Mock ¶
type Mock struct { Request MockRequest `json:"request,omitempty" yaml:"request"` Response *MockResponse `json:"response,omitempty" yaml:"response,omitempty"` Context *MockContext `json:"context,omitempty" yaml:"context,omitempty"` }
type MockBuilder ¶ added in v0.2.6
type MockBuilder struct {
// contains filtered or unexported fields
}
func NewMockBuilder ¶ added in v0.2.6
func NewMockBuilder() *MockBuilder
func (*MockBuilder) AddRequestBodyJSON ¶ added in v0.2.6
func (mb *MockBuilder) AddRequestBodyJSON(key string, body StringMatcher) *MockBuilder
func (*MockBuilder) AddRequestHeader ¶ added in v0.2.6
func (mb *MockBuilder) AddRequestHeader(name string, value StringMatcher) *MockBuilder
func (*MockBuilder) AddRequestQueryParam ¶ added in v0.2.6
func (mb *MockBuilder) AddRequestQueryParam(name string, value StringMatcher) *MockBuilder
func (*MockBuilder) AddResponseHeader ¶ added in v0.2.6
func (mb *MockBuilder) AddResponseHeader(name string, value string) *MockBuilder
func (*MockBuilder) Mock ¶ added in v0.2.6
func (mb *MockBuilder) Mock() *Mock
func (*MockBuilder) SetContextTimes ¶ added in v0.2.6
func (mb *MockBuilder) SetContextTimes(times uint) *MockBuilder
func (*MockBuilder) SetRequestBodyString ¶ added in v0.2.6
func (mb *MockBuilder) SetRequestBodyString(body StringMatcher) *MockBuilder
func (*MockBuilder) SetRequestHeaders ¶ added in v0.2.6
func (mb *MockBuilder) SetRequestHeaders(headers MultiMapMatcher) *MockBuilder
func (*MockBuilder) SetRequestMethod ¶ added in v0.2.6
func (mb *MockBuilder) SetRequestMethod(method StringMatcher) *MockBuilder
func (*MockBuilder) SetRequestPath ¶ added in v0.2.6
func (mb *MockBuilder) SetRequestPath(path StringMatcher) *MockBuilder
func (*MockBuilder) SetRequestQueryParams ¶ added in v0.2.6
func (mb *MockBuilder) SetRequestQueryParams(queryParams MultiMapMatcher) *MockBuilder
func (*MockBuilder) SetResponseBody ¶ added in v0.2.6
func (mb *MockBuilder) SetResponseBody(body string) *MockBuilder
func (*MockBuilder) SetResponseDelay ¶ added in v0.2.6
func (mb *MockBuilder) SetResponseDelay(min, max time.Duration) *MockBuilder
func (*MockBuilder) SetResponseHeaders ¶ added in v0.2.6
func (mb *MockBuilder) SetResponseHeaders(headers MapStringSlice) *MockBuilder
func (*MockBuilder) SetResponseStatus ¶ added in v0.2.6
func (mb *MockBuilder) SetResponseStatus(status int) *MockBuilder
type MockContext ¶ added in v0.2.6
type MockContext struct {
Times uint `json:"times" yaml:"times"`
}
type MockRequest ¶ added in v0.2.0
type MockRequest struct { Path StringMatcher `json:"path" yaml:"path"` Method StringMatcher `json:"method" yaml:"method"` Body *BodyMatcher `json:"body,omitempty" yaml:"body,omitempty"` QueryParams MultiMapMatcher `json:"query_params,omitempty" yaml:"query_params,omitempty"` Headers MultiMapMatcher `json:"headers,omitempty" yaml:"headers,omitempty"` }
type MockResponse ¶ added in v0.2.0
type MockResponse struct { Body string `json:"body,omitempty" yaml:"body,omitempty"` Status int `json:"status" yaml:"status"` Delay Delay `json:"delay,omitempty" yaml:"delay,omitempty"` Headers MapStringSlice `json:"headers,omitempty" yaml:"headers,omitempty"` }
type MultiMapMatcher ¶ added in v0.2.0
type MultiMapMatcher map[string]StringMatcherSlice
type Request ¶
type Request struct { Method Method BaseURL string // e.g. https://api.sendgrid.com Headers map[string]string QueryParams map[string]string Body []byte }
Request holds the request to an API Call.
type Response ¶
type Response struct { StatusCode int // e.g. 200 Body string // e.g. {"result: success"} Headers map[string][]string // e.g. map[X-Ratelimit-Limit:[600]] }
Response holds the response from an API call.
func BuildResponse ¶
BuildResponse builds the response struct.
type RestError ¶
type RestError struct {
Response *Response
}
RestError is a struct for an error handling.
type StringMatcher ¶ added in v0.2.0
type StringMatcher struct { Matcher string `json:"matcher" yaml:"matcher,flow"` Value string `json:"value" yaml:"value,flow"` }
func ShouldBeEmpty ¶ added in v0.2.6
func ShouldBeEmpty(value string) StringMatcher
func ShouldContainSubstring ¶ added in v0.2.6
func ShouldContainSubstring(value string) StringMatcher
func ShouldEndWith ¶ added in v0.2.6
func ShouldEndWith(value string) StringMatcher
func ShouldEqual ¶ added in v0.2.6
func ShouldEqual(value string) StringMatcher
func ShouldEqualJSON ¶ added in v0.2.6
func ShouldEqualJSON(value string) StringMatcher
func ShouldMatch ¶ added in v0.2.6
func ShouldMatch(value string) StringMatcher
func ShouldNotBeEmpty ¶ added in v0.2.6
func ShouldNotBeEmpty(value string) StringMatcher
func ShouldNotContainSubstring ¶ added in v0.2.6
func ShouldNotContainSubstring(value string) StringMatcher
func ShouldNotEndWith ¶ added in v0.2.6
func ShouldNotEndWith(value string) StringMatcher
func ShouldNotEqual ¶ added in v0.2.6
func ShouldNotEqual(value string) StringMatcher
func ShouldNotMatch ¶ added in v0.2.6
func ShouldNotMatch(value string) StringMatcher
func ShouldNotResemble ¶ added in v0.2.6
func ShouldNotResemble(value string) StringMatcher
func ShouldNotStartWith ¶ added in v0.2.6
func ShouldNotStartWith(value string) StringMatcher
func ShouldResemble ¶ added in v0.2.6
func ShouldResemble(value string) StringMatcher
func ShouldStartWith ¶ added in v0.2.6
func ShouldStartWith(value string) StringMatcher
type StringMatcherSlice ¶ added in v0.2.0
type StringMatcherSlice []StringMatcher
type StringSlice ¶ added in v0.2.0
type StringSlice []string
Click to show internal directories.
Click to hide internal directories.