mock

package
v0.7.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2023 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewResponse

func NewResponse(req *http.Request, code int, body string) *http.Response

func WildcardMatch

func WildcardMatch(str string, pattern string) bool

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

func (h *Handler) ThenReply(statusCode int) *Handler

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

func (h *Handler) WithBody(body string) *Handler

WithBody adds body to the handler response. It can be called either before or after ThenReply()

func (*Handler) WithCustomStatus

func (h *Handler) WithCustomStatus(status string) *Handler

WithCustomStatus allows to change the standard HTTP response text to a custom one.

type HandlerFunc

type HandlerFunc func(req *http.Request) (*http.Response, error)

type HttpClient

type HttpClient struct {
	// contains filtered or unexported fields
}

func NewHttpClient

func NewHttpClient() *HttpClient

func (*HttpClient) Do

func (c *HttpClient) Do(req *http.Request) (*http.Response, error)

Do mocks the http.Client.Do() function

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

func (*HttpClient) WhenWc

func (c *HttpClient) WhenWc(method string, url string) *Handler

WhenWc creates and returns a handler which will be used for the wildcard match of the request to the specified HTTP method and URL path pattern

type Interaction

type Interaction struct {
	Handler *Handler
	Req     *http.Request
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL