Documentation
¶
Index ¶
- func NewResponse(req *http.Request, code int, body string) *http.Response
- func WildcardMatch(str string, pattern string) bool
- type Handler
- type HandlerFunc
- type HttpClient
- func (c *HttpClient) Do(req *http.Request) (*http.Response, error)
- func (c *HttpClient) Interactions() []Interaction
- func (c *HttpClient) Reset() *HttpClient
- func (c *HttpClient) When(method string, url string) *Handler
- func (c *HttpClient) WhenAnyMethod(url string) *Handler
- func (c *HttpClient) WhenAnyMethodWc(url string) *Handler
- func (c *HttpClient) WhenWc(method string, url string) *Handler
- type Interaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WildcardMatch ¶
WildcardMatch matches the specified string against the supplied pattern with wildcard characters ('*' and '?'). It uses the recursive algorithm which is not very efficient, its complexity can be up to O(N^k), where k = (number of asterisks in the pattern + 1). But it could be slightly faster than the matrix algorithm when the pattern contains just one asterisk.
Types ¶
type Handler ¶
type Handler struct { Interactions int // contains filtered or unexported fields }
func (*Handler) ThenCall ¶
func (h *Handler) ThenCall(function HandlerFunc) *Handler
ThenCall tells the handler to call provided function instead of simply returning the response. This function can implement some more complex logic
func (*Handler) ThenReply ¶
ThenReply sets the HTTP response status code for the handler. The HTTP response text is set automatically according to the response status code
func (*Handler) WithBody ¶
WithBody adds body to the handler response. It can be called either before or after ThenReply()
func (*Handler) WithCustomStatus ¶
WithCustomStatus allows to change the standard HTTP response text to a custom one.
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func NewHttpClient ¶
func NewHttpClient() *HttpClient
func (*HttpClient) Interactions ¶
func (c *HttpClient) Interactions() []Interaction
Interactions returns list of all interactions (handler + request) which were registered by the client
func (*HttpClient) Reset ¶
func (c *HttpClient) Reset() *HttpClient
Reset resets the entire HttpClient and deletes all handlers
func (*HttpClient) When ¶
func (c *HttpClient) When(method string, url string) *Handler
When creates and returns a handler which will be used for the exact match of the request to the specified HTTP method and URL path
func (*HttpClient) WhenAnyMethod ¶
func (c *HttpClient) WhenAnyMethod(url string) *Handler
WhenAnyMethod creates and returns a handler which will be used for the exact match of the request to the specified URL path and any HTTP method
func (*HttpClient) WhenAnyMethodWc ¶
func (c *HttpClient) WhenAnyMethodWc(url string) *Handler
WhenAnyMethodWc creates and returns a handler which will be used for the wildcard match of the request to the specified URL path pattern and any HTTP method