Documentation ¶
Overview ¶
Package wiremock is client for WireMock API. WireMock is a simulator for HTTP-based APIs. Some might consider it a service virtualization tool or a mock server.
HTTP request:
POST /example?firstName=John&lastName=Any string other than "Gray" HTTP/1.1 Host: 0.0.0.0:8080 x-session: somefingerprintsome Content-Type: application/json Content-Length: 23 {"meta": "information"}
With response:
Status: 400 Bad Request "Content-Type": "application/json" {"code": 400, "detail": "detail"}
Stub:
client := wiremock.NewClient("http://0.0.0.0:8080") client.StubFor(wiremock.Post(wiremock.URLPathEqualTo("/example")). WithQueryParam("firstName", wiremock.EqualTo("John")). WithQueryParam("lastName", wiremock.NotMatching("Gray")). WithBodyPattern(wiremock.EqualToJson(`{"meta": "information"}`)). WithHeader("x-session", wiremock.Matching("^\\S+fingerprint\\S+$")). WillReturnResponse( wiremock.NewResponse(). WithStatus(http.StatusBadRequest). WithHeader("Content-Type", "application/json"). WithBody(`{"code": 400, "detail": "detail"}`), ). AtPriority(1))
The client should reset all made stubs after tests:
client := wiremock.NewClient("http://0.0.0.0:8080") defer wiremock.Reset() client.StubFor(wiremock.Get(wiremock.URLPathEqualTo("/example"))) client.StubFor(wiremock.Get(wiremock.URLPathEqualTo("/example/1"))) // ...
To avoid conflicts, you can delete individual rules:
client := wiremock.NewClient("http://0.0.0.0:8080") exampleStubRule := wiremock.Get(wiremock.URLPathEqualTo("/example")) client.StubFor(exampleStubRule) client.StubFor(wiremock.Get(wiremock.URLPathEqualTo("/example/1"))) // ... client.DeleteStub(exampleStubRule)
You can verify if a request has been made that matches the mapping.
client := wiremock.NewClient("http://0.0.0.0:8080") exampleStubRule := wiremock.Get(wiremock.URLPathEqualTo("/example")) client.StubFor(exampleStubRule) // ... client.Verify(exampleStubRule.Request(), 1)
Index ¶
- Constants
- type BasicParamMatcher
- func Absent() BasicParamMatcher
- func Contains(param string) BasicParamMatcher
- func EqualTo(value string) BasicParamMatcher
- func EqualToIgnoreCase(value string) BasicParamMatcher
- func EqualToJson(param string, equalJsonFlags ...EqualFlag) BasicParamMatcher
- func EqualToXml(param string) BasicParamMatcher
- func Matching(param string) BasicParamMatcher
- func MatchingJsonPath(param string) BasicParamMatcher
- func MatchingXPath(param string) BasicParamMatcher
- func NotContains(param string) BasicParamMatcher
- func NotMatching(param string) BasicParamMatcher
- func StartsWith(prefix string) BasicParamMatcher
- type Client
- func (c *Client) Clear() error
- func (c *Client) DeleteStub(s *StubRule) error
- func (c *Client) DeleteStubByID(id string) error
- func (c *Client) GetCountRequests(r *Request) (int64, error)
- func (c *Client) Reset() error
- func (c *Client) ResetAllScenarios() error
- func (c *Client) StubFor(stubRule *StubRule) error
- func (c *Client) Verify(r *Request, expectedCount int64) (bool, error)
- type DelayInterface
- type EqualFlag
- type Fault
- type LogicalMatcher
- type MatcherInterface
- type MultiValueMatcher
- type MultiValueMatchingStrategy
- type MultipartMatchingType
- type MultipartPattern
- func (m *MultipartPattern) MarshalJSON() ([]byte, error)
- func (m *MultipartPattern) ParseMultipartPattern() map[string]interface{}
- func (m *MultipartPattern) WithAllMatchingType() *MultipartPattern
- func (m *MultipartPattern) WithAnyMatchingType() *MultipartPattern
- func (m *MultipartPattern) WithBodyPattern(matcher BasicParamMatcher) *MultipartPattern
- func (m *MultipartPattern) WithHeader(header string, matcher MatcherInterface) *MultipartPattern
- func (m *MultipartPattern) WithMatchingType(matchingType MultipartMatchingType) *MultipartPattern
- func (m *MultipartPattern) WithName(name string) *MultipartPattern
- type MultipartPatternInterface
- type ParamMatchingStrategy
- type Request
- func (r *Request) MarshalJSON() ([]byte, error)
- func (r *Request) WithBasicAuth(username, password string) *Request
- func (r *Request) WithBodyPattern(matcher BasicParamMatcher) *Request
- func (r *Request) WithCookie(cookie string, matcher BasicParamMatcher) *Request
- func (r *Request) WithFormParameter(name string, matcher BasicParamMatcher) *Request
- func (r *Request) WithHeader(header string, matcher MatcherInterface) *Request
- func (r *Request) WithHost(host BasicParamMatcher) *Request
- func (r *Request) WithMethod(method string) *Request
- func (r *Request) WithMultipartPattern(pattern *MultipartPattern) *Request
- func (r *Request) WithPort(port int64) *Request
- func (r *Request) WithQueryParam(param string, matcher MatcherInterface) *Request
- func (r *Request) WithScheme(scheme string) *Request
- func (r *Request) WithURLMatched(urlMatcher URLMatcherInterface) *Request
- type Response
- func (r Response) ParseResponse() map[string]interface{}
- func (r Response) WithBinaryBody(body []byte) Response
- func (r Response) WithBody(body string) Response
- func (r Response) WithBodyFile(fileName string) Response
- func (r Response) WithChunkedDribbleDelay(numberOfChunks int64, totalDuration time.Duration) Response
- func (r Response) WithDelay(delay DelayInterface) Response
- func (r Response) WithFault(fault Fault) Response
- func (r Response) WithFixedDelay(delay time.Duration) Response
- func (r Response) WithHeader(key, value string) Response
- func (r Response) WithHeaders(headers map[string]string) Response
- func (r Response) WithJSONBody(body interface{}) Response
- func (r Response) WithLogNormalRandomDelay(median time.Duration, sigma float64) Response
- func (r Response) WithStatus(status int64) Response
- func (r Response) WithUniformRandomDelay(lower, upper time.Duration) Response
- type ResponseInterface
- type StringValueMatcher
- type StubRule
- func Delete(urlMatchingPair URLMatcher) *StubRule
- func Get(urlMatchingPair URLMatcher) *StubRule
- func NewStubRule(method string, urlMatcher URLMatcher) *StubRule
- func Patch(urlMatchingPair URLMatcher) *StubRule
- func Post(urlMatchingPair URLMatcher) *StubRule
- func Put(urlMatchingPair URLMatcher) *StubRule
- func (s *StubRule) AtPriority(priority int64) *StubRule
- func (s *StubRule) InScenario(scenarioName string) *StubRule
- func (s *StubRule) MarshalJSON() ([]byte, error)
- func (s *StubRule) Request() *Request
- func (s *StubRule) UUID() string
- func (s *StubRule) WhenScenarioStateIs(scenarioState string) *StubRule
- func (s *StubRule) WillReturn(body string, headers map[string]string, status int64) *StubRuledeprecated
- func (s *StubRule) WillReturnBinary(body []byte, headers map[string]string, status int64) *StubRuledeprecated
- func (s *StubRule) WillReturnFileContent(bodyFileName string, headers map[string]string, status int64) *StubRuledeprecated
- func (s *StubRule) WillReturnJSON(json interface{}, headers map[string]string, status int64) *StubRuledeprecated
- func (s *StubRule) WillReturnResponse(response ResponseInterface) *StubRule
- func (s *StubRule) WillSetStateTo(scenarioState string) *StubRule
- func (s *StubRule) WithAuthToken(tokenMatcher BasicParamMatcher) *StubRule
- func (s *StubRule) WithBasicAuth(username, password string) *StubRule
- func (s *StubRule) WithBearerToken(tokenMatcher BasicParamMatcher) *StubRule
- func (s *StubRule) WithBodyPattern(matcher BasicParamMatcher) *StubRule
- func (s *StubRule) WithCookie(cookie string, matcher BasicParamMatcher) *StubRule
- func (s *StubRule) WithDigestAuth(matcher BasicParamMatcher) *StubRule
- func (s *StubRule) WithFixedDelayMilliseconds(delay time.Duration) *StubRuledeprecated
- func (s *StubRule) WithFormParameter(param string, matcher BasicParamMatcher) *StubRule
- func (s *StubRule) WithHeader(header string, matcher MatcherInterface) *StubRule
- func (s *StubRule) WithHost(host BasicParamMatcher) *StubRule
- func (s *StubRule) WithMultipartPattern(pattern *MultipartPattern) *StubRule
- func (s *StubRule) WithPort(port int64) *StubRule
- func (s *StubRule) WithPostServeAction(extensionName string, webhook WebhookInterface) *StubRule
- func (s *StubRule) WithQueryParam(param string, matcher MatcherInterface) *StubRule
- func (s *StubRule) WithScheme(scheme string) *StubRule
- type URLMatcher
- type URLMatcherInterface
- type URLMatchingStrategy
- type Webhook
- func (w Webhook) MarshalJSON() ([]byte, error)
- func (w Webhook) ParseWebhook() map[string]interface{}
- func (w Webhook) WithBody(body string) Webhook
- func (w Webhook) WithDelay(delay DelayInterface) Webhook
- func (w Webhook) WithFixedDelay(delay time.Duration) Webhook
- func (w Webhook) WithHeader(key string, value string) Webhook
- func (w Webhook) WithLogNormalRandomDelay(median time.Duration, sigma float64) Webhook
- func (w Webhook) WithMethod(method string) Webhook
- func (w Webhook) WithName(name string) WebhookInterface
- func (w Webhook) WithURL(url string) Webhook
- func (w Webhook) WithUniformRandomDelay(lower, upper time.Duration) Webhook
- type WebhookInterface
Constants ¶
const ( MultipartMatchingTypeAny = "ANY" MultipartMatchingTypeAll = "ALL" )
const ScenarioStateStarted = "Started"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BasicParamMatcher ¶
type BasicParamMatcher interface { json.Marshaler ParseMatcher() map[string]interface{} Or(stringMatcher BasicParamMatcher) BasicParamMatcher And(stringMatcher BasicParamMatcher) BasicParamMatcher }
func Absent ¶
func Absent() BasicParamMatcher
Absent returns a matcher that matches when the parameter is absent.
func Contains ¶
func Contains(param string) BasicParamMatcher
Contains returns a matcher that matches when the parameter contains the specified value.
func EqualTo ¶
func EqualTo(value string) BasicParamMatcher
EqualTo returns a matcher that matches when the parameter equals the specified value.
func EqualToIgnoreCase ¶
func EqualToIgnoreCase(value string) BasicParamMatcher
EqualToIgnoreCase returns a matcher that matches when the parameter equals the specified value, ignoring case.
func EqualToJson ¶
func EqualToJson(param string, equalJsonFlags ...EqualFlag) BasicParamMatcher
EqualToJson returns a matcher that matches when the parameter is equal to the specified JSON.
func EqualToXml ¶
func EqualToXml(param string) BasicParamMatcher
EqualToXml returns a matcher that matches when the parameter is equal to the specified XML.
func Matching ¶
func Matching(param string) BasicParamMatcher
Matching returns a matcher that matches when the parameter matches the specified regular expression.
func MatchingJsonPath ¶
func MatchingJsonPath(param string) BasicParamMatcher
MatchingJsonPath returns a matcher that matches when the parameter matches the specified JSON path.
func MatchingXPath ¶
func MatchingXPath(param string) BasicParamMatcher
MatchingXPath returns a matcher that matches when the parameter matches the specified XPath.
func NotContains ¶
func NotContains(param string) BasicParamMatcher
NotContains returns a matcher that matches when the parameter does not contain the specified value.
func NotMatching ¶
func NotMatching(param string) BasicParamMatcher
NotMatching returns a matcher that matches when the parameter does not match the specified regular expression.
func StartsWith ¶ added in v1.8.0
func StartsWith(prefix string) BasicParamMatcher
StartsWith returns a matcher that matches when the parameter starts with the specified prefix. Matches also when prefix alone is the whole expression
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client implements requests to the wiremock server.
func (*Client) DeleteStub ¶
DeleteStub deletes stub mapping.
func (*Client) DeleteStubByID ¶
DeleteStubByID deletes stub by id.
func (*Client) GetCountRequests ¶
GetCountRequests gives count requests by criteria.
func (*Client) Reset ¶
Reset restores stub mappings to the defaults defined back in the backing store.
func (*Client) ResetAllScenarios ¶
ResetAllScenarios resets back to start of the state of all configured scenarios.
type DelayInterface ¶
type DelayInterface interface {
ParseDelay() map[string]interface{}
}
func NewFixedDelay ¶
func NewFixedDelay(delay time.Duration) DelayInterface
func NewLogNormalRandomDelay ¶
func NewLogNormalRandomDelay(median time.Duration, sigma float64) DelayInterface
func NewUniformRandomDelay ¶
func NewUniformRandomDelay(lower, upper time.Duration) DelayInterface
type LogicalMatcher ¶
type LogicalMatcher struct {
// contains filtered or unexported fields
}
func And ¶
func And(matchers ...BasicParamMatcher) LogicalMatcher
And returns a logical AND of the list of matchers.
func Or ¶
func Or(matchers ...BasicParamMatcher) LogicalMatcher
Or returns a logical OR of the list of matchers.
func (LogicalMatcher) And ¶
func (m LogicalMatcher) And(matcher BasicParamMatcher) BasicParamMatcher
And returns a logical AND of the current matcher and the given matcher.
func (LogicalMatcher) MarshalJSON ¶
func (m LogicalMatcher) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the matcher.
func (LogicalMatcher) Or ¶
func (m LogicalMatcher) Or(matcher BasicParamMatcher) BasicParamMatcher
Or returns a logical OR of the current matcher and the given matcher.
func (LogicalMatcher) ParseMatcher ¶
func (m LogicalMatcher) ParseMatcher() map[string]interface{}
ParseMatcher returns the map representation of the structure.
type MatcherInterface ¶
type MultiValueMatcher ¶
type MultiValueMatcher struct {
// contains filtered or unexported fields
}
func HasExactly ¶
func HasExactly(matchers ...BasicParamMatcher) MultiValueMatcher
HasExactly returns a matcher that matches when the parameter has exactly the specified values.
func Includes ¶
func Includes(matchers ...BasicParamMatcher) MultiValueMatcher
Includes returns a matcher that matches when the parameter includes the specified values.
func (MultiValueMatcher) MarshalJSON ¶
func (m MultiValueMatcher) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the matcher.
func (MultiValueMatcher) ParseMatcher ¶
func (m MultiValueMatcher) ParseMatcher() map[string]interface{}
ParseMatcher returns the map representation of the structure.
type MultiValueMatchingStrategy ¶
type MultiValueMatchingStrategy string
MultiValueMatchingStrategy is enum multi value matching type.
const ( ParamHasExactly MultiValueMatchingStrategy = "hasExactly" ParamIncludes MultiValueMatchingStrategy = "includes" )
type MultipartMatchingType ¶
type MultipartMatchingType string
type MultipartPattern ¶
type MultipartPattern struct {
// contains filtered or unexported fields
}
func NewMultipartPattern ¶
func NewMultipartPattern() *MultipartPattern
func (*MultipartPattern) MarshalJSON ¶
func (m *MultipartPattern) MarshalJSON() ([]byte, error)
MarshalJSON gives valid JSON or error.
func (*MultipartPattern) ParseMultipartPattern ¶
func (m *MultipartPattern) ParseMultipartPattern() map[string]interface{}
func (*MultipartPattern) WithAllMatchingType ¶
func (m *MultipartPattern) WithAllMatchingType() *MultipartPattern
func (*MultipartPattern) WithAnyMatchingType ¶
func (m *MultipartPattern) WithAnyMatchingType() *MultipartPattern
func (*MultipartPattern) WithBodyPattern ¶
func (m *MultipartPattern) WithBodyPattern(matcher BasicParamMatcher) *MultipartPattern
func (*MultipartPattern) WithHeader ¶
func (m *MultipartPattern) WithHeader(header string, matcher MatcherInterface) *MultipartPattern
func (*MultipartPattern) WithMatchingType ¶
func (m *MultipartPattern) WithMatchingType(matchingType MultipartMatchingType) *MultipartPattern
func (*MultipartPattern) WithName ¶
func (m *MultipartPattern) WithName(name string) *MultipartPattern
type ParamMatchingStrategy ¶
type ParamMatchingStrategy string
ParamMatchingStrategy is enum params matching type.
const ( ParamEqualTo ParamMatchingStrategy = "equalTo" ParamMatches ParamMatchingStrategy = "matches" ParamContains ParamMatchingStrategy = "contains" ParamEqualToXml ParamMatchingStrategy = "equalToXml" ParamEqualToJson ParamMatchingStrategy = "equalToJson" ParamMatchesXPath ParamMatchingStrategy = "matchesXPath" ParamMatchesJsonPath ParamMatchingStrategy = "matchesJsonPath" ParamAbsent ParamMatchingStrategy = "absent" ParamDoesNotMatch ParamMatchingStrategy = "doesNotMatch" ParamDoesNotContains ParamMatchingStrategy = "doesNotContain" )
Types of params matching.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
A Request is the part of StubRule describing the matching of the http request
func NewRequest ¶
func NewRequest(method string, urlMatcher URLMatcherInterface) *Request
NewRequest constructs minimum possible Request
func (*Request) MarshalJSON ¶
MarshalJSON gives valid JSON or error.
func (*Request) WithBasicAuth ¶
WithBasicAuth adds basic auth credentials to Request
func (*Request) WithBodyPattern ¶
func (r *Request) WithBodyPattern(matcher BasicParamMatcher) *Request
WithBodyPattern adds body pattern to list
func (*Request) WithCookie ¶
func (r *Request) WithCookie(cookie string, matcher BasicParamMatcher) *Request
WithCookie is fluent-setter for cookie
func (*Request) WithFormParameter ¶ added in v1.9.0
func (r *Request) WithFormParameter(name string, matcher BasicParamMatcher) *Request
WithFormParameter adds form parameter to list
func (*Request) WithHeader ¶
func (r *Request) WithHeader(header string, matcher MatcherInterface) *Request
WithHeader add header to header list
func (*Request) WithHost ¶
func (r *Request) WithHost(host BasicParamMatcher) *Request
WithHost is fluent-setter for host
func (*Request) WithMethod ¶
WithMethod is fluent-setter for http verb
func (*Request) WithMultipartPattern ¶
func (r *Request) WithMultipartPattern(pattern *MultipartPattern) *Request
WithMultipartPattern adds multipart pattern to list
func (*Request) WithQueryParam ¶
func (r *Request) WithQueryParam(param string, matcher MatcherInterface) *Request
WithQueryParam add param to query param list
func (*Request) WithScheme ¶
WithScheme is fluent-setter for scheme
func (*Request) WithURLMatched ¶
func (r *Request) WithURLMatched(urlMatcher URLMatcherInterface) *Request
WithURLMatched is fluent-setter url matcher
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func NewResponse ¶
func NewResponse() Response
func (Response) ParseResponse ¶
func (Response) WithBinaryBody ¶
WithBinaryBody sets binary body for response
func (Response) WithBodyFile ¶
WithBodyFile sets body file name for response
func (Response) WithChunkedDribbleDelay ¶
func (r Response) WithChunkedDribbleDelay(numberOfChunks int64, totalDuration time.Duration) Response
WithChunkedDribbleDelay sets chunked dribble delay for response
func (Response) WithDelay ¶
func (r Response) WithDelay(delay DelayInterface) Response
WithDelay sets delay for response
func (Response) WithFixedDelay ¶
WithFixedDelay sets fixed delay milliseconds for response
func (Response) WithHeader ¶
WithHeader sets header for response
func (Response) WithHeaders ¶
WithHeaders sets headers for response
func (Response) WithJSONBody ¶
WithJSONBody sets json body for response
func (Response) WithLogNormalRandomDelay ¶
WithLogNormalRandomDelay sets log normal random delay for response
func (Response) WithStatus ¶
WithStatus sets status for response
type ResponseInterface ¶
type ResponseInterface interface {
ParseResponse() map[string]interface{}
}
type StringValueMatcher ¶
type StringValueMatcher struct {
// contains filtered or unexported fields
}
func NewStringValueMatcher ¶
func NewStringValueMatcher(strategy ParamMatchingStrategy, value string, flags ...string) StringValueMatcher
NewStringValueMatcher creates a new StringValueMatcher.
func (StringValueMatcher) And ¶
func (m StringValueMatcher) And(matcher BasicParamMatcher) BasicParamMatcher
And returns a logical AND of the two matchers.
func (StringValueMatcher) MarshalJSON ¶
func (m StringValueMatcher) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the matcher.
func (StringValueMatcher) Or ¶
func (m StringValueMatcher) Or(matcher BasicParamMatcher) BasicParamMatcher
Or returns a logical OR of the two matchers.
func (StringValueMatcher) ParseMatcher ¶
func (m StringValueMatcher) ParseMatcher() map[string]interface{}
ParseMatcher returns the map representation of the structure.
type StubRule ¶
type StubRule struct {
// contains filtered or unexported fields
}
StubRule is struct of http Request body to WireMock
func Delete ¶
func Delete(urlMatchingPair URLMatcher) *StubRule
Delete returns *StubRule for DELETE method.
func NewStubRule ¶
func NewStubRule(method string, urlMatcher URLMatcher) *StubRule
NewStubRule returns a new *StubRule.
func Patch ¶
func Patch(urlMatchingPair URLMatcher) *StubRule
Patch returns *StubRule for PATCH method.
func (*StubRule) AtPriority ¶
AtPriority sets priority and returns *StubRule
func (*StubRule) InScenario ¶
InScenario sets scenarioName and returns *StubRule
func (*StubRule) MarshalJSON ¶
MarshalJSON makes json body for http Request
func (*StubRule) WhenScenarioStateIs ¶
WhenScenarioStateIs sets requiredScenarioState and returns *StubRule
func (*StubRule) WillReturnBinary
deprecated
func (*StubRule) WillReturnFileContent
deprecated
func (s *StubRule) WillReturnFileContent(bodyFileName string, headers map[string]string, status int64) *StubRule
Deprecated: Use WillReturnResponse(NewResponse().WithBodyFile(file).WithHeaders(headers).WithStatus(status)) instead WillReturnFileContent sets response with some file content and returns *StubRule
func (*StubRule) WillReturnJSON
deprecated
func (*StubRule) WillReturnResponse ¶
func (s *StubRule) WillReturnResponse(response ResponseInterface) *StubRule
WillReturnResponse sets response and returns *StubRule
func (*StubRule) WillSetStateTo ¶
WillSetStateTo sets newScenarioState and returns *StubRule
func (*StubRule) WithAuthToken ¶ added in v1.8.0
func (s *StubRule) WithAuthToken(tokenMatcher BasicParamMatcher) *StubRule
WithAuthToken adds Authorization header with Token auth method *StubRule
func (*StubRule) WithBasicAuth ¶
WithBasicAuth adds basic auth credentials
func (*StubRule) WithBearerToken ¶ added in v1.8.0
func (s *StubRule) WithBearerToken(tokenMatcher BasicParamMatcher) *StubRule
WithBearerToken adds Authorization header with Bearer auth method *StubRule
func (*StubRule) WithBodyPattern ¶
func (s *StubRule) WithBodyPattern(matcher BasicParamMatcher) *StubRule
WithBodyPattern adds body pattern and returns *StubRule
func (*StubRule) WithCookie ¶
func (s *StubRule) WithCookie(cookie string, matcher BasicParamMatcher) *StubRule
WithCookie adds cookie and returns *StubRule
func (*StubRule) WithDigestAuth ¶ added in v1.8.0
func (s *StubRule) WithDigestAuth(matcher BasicParamMatcher) *StubRule
WithDigestAuth adds Authorization header with Digest auth method *StubRule
func (*StubRule) WithFixedDelayMilliseconds
deprecated
func (*StubRule) WithFormParameter ¶ added in v1.9.0
func (s *StubRule) WithFormParameter(param string, matcher BasicParamMatcher) *StubRule
WithFormParameter adds form parameter and returns *StubRule
func (*StubRule) WithHeader ¶
func (s *StubRule) WithHeader(header string, matcher MatcherInterface) *StubRule
WithHeader adds header to Headers and returns *StubRule
func (*StubRule) WithHost ¶
func (s *StubRule) WithHost(host BasicParamMatcher) *StubRule
WithHost adds host and returns *StubRule
func (*StubRule) WithMultipartPattern ¶
func (s *StubRule) WithMultipartPattern(pattern *MultipartPattern) *StubRule
WithMultipartPattern adds multipart body pattern and returns *StubRule
func (*StubRule) WithPostServeAction ¶
func (s *StubRule) WithPostServeAction(extensionName string, webhook WebhookInterface) *StubRule
func (*StubRule) WithQueryParam ¶
func (s *StubRule) WithQueryParam(param string, matcher MatcherInterface) *StubRule
WithQueryParam adds query param and returns *StubRule
func (*StubRule) WithScheme ¶
WithScheme adds scheme and returns *StubRule
type URLMatcher ¶
type URLMatcher struct {
// contains filtered or unexported fields
}
URLMatcher is structure for defining the type of url matching.
func URLEqualTo ¶
func URLEqualTo(url string) URLMatcher
URLEqualTo returns URLMatcher with URLEqualToRule matching strategy.
func URLMatching ¶
func URLMatching(url string) URLMatcher
URLMatching returns URLMatcher with URLMatchingRule matching strategy.
func URLPathEqualTo ¶
func URLPathEqualTo(url string) URLMatcher
URLPathEqualTo returns URLMatcher with URLPathEqualToRule matching strategy.
func URLPathMatching ¶
func URLPathMatching(url string) URLMatcher
URLPathMatching returns URLMatcher with URLPathMatchingRule matching strategy.
func (URLMatcher) Strategy ¶
func (m URLMatcher) Strategy() URLMatchingStrategy
Strategy returns URLMatchingStrategy of URLMatcher.
type URLMatcherInterface ¶
type URLMatcherInterface interface { Strategy() URLMatchingStrategy Value() string }
URLMatcherInterface is pair URLMatchingStrategy and string matched value
type URLMatchingStrategy ¶
type URLMatchingStrategy string
URLMatchingStrategy is enum url matching type.
const ( URLEqualToRule URLMatchingStrategy = "url" URLPathEqualToRule URLMatchingStrategy = "urlPath" URLPathMatchingRule URLMatchingStrategy = "urlPathPattern" URLMatchingRule URLMatchingStrategy = "urlPattern" )
Types of url matching.
type Webhook ¶
type Webhook struct {
// contains filtered or unexported fields
}
func NewWebhook ¶
func NewWebhook() Webhook
func (Webhook) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Webhook) ParseWebhook ¶
ParseWebhook returns a map representation of the webhook.
func (Webhook) WithDelay ¶
func (w Webhook) WithDelay(delay DelayInterface) Webhook
WithDelay sets the delay of the webhook.
func (Webhook) WithFixedDelay ¶
WithFixedDelay sets the fixed delay of the webhook.
func (Webhook) WithHeader ¶
WithHeader sets a header of the webhook.
func (Webhook) WithLogNormalRandomDelay ¶
WithLogNormalRandomDelay sets the log normal delay of the webhook.
func (Webhook) WithMethod ¶
WithMethod sets the HTTP method of the webhook.
func (Webhook) WithName ¶
func (w Webhook) WithName(name string) WebhookInterface
WithName sets the name of the webhook and returns the webhook.
type WebhookInterface ¶
type WebhookInterface interface { json.Marshaler WithName(name string) WebhookInterface ParseWebhook() map[string]interface{} }