fetchermock

package
v0.0.0-...-612c04b Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is used to mock the fetcher.Client

func NewClient

func NewClient(c context.Context, opts ...ClientOption) (*Client, error)

NewClient returns a new Client with the given options executed

func (*Client) Delete

func (cl *Client) Delete(c context.Context, url string, opts ...fetcher.RequestOption) (*fetcher.Response, error)

Delete is a helper func for Do, setting the Method internally

func (*Client) Do

func (cl *Client) Do(c context.Context, req *fetcher.Request) (*fetcher.Response, error)

Do mocks the execution of a request by matching it up with an expectedRequest If no matching expectedRequests are found, fetchermock will exit with errors

func (*Client) ExpectRequest

func (cl *Client) ExpectRequest(c context.Context, method, url string, opts ...ExpectedRequestOption) error

ExpectRequest creates an ExpectedRequest and adds it to the cl.expectedRequests

func (*Client) Get

func (cl *Client) Get(c context.Context, url string, opts ...fetcher.RequestOption) (*fetcher.Response, error)

Get is a helper func for Do, setting the Method internally

func (*Client) Head

func (cl *Client) Head(c context.Context, url string, opts ...fetcher.RequestOption) (*fetcher.Response, error)

Head is a helper func for Do, setting the Method internally

func (*Client) NewRequest

func (cl *Client) NewRequest(c context.Context, method, url string, opts ...fetcher.RequestOption) (*fetcher.Request, error)

NewRequest returns a new Request with the given method/url and options executed

func (*Client) Patch

func (cl *Client) Patch(c context.Context, url string, opts ...fetcher.RequestOption) (*fetcher.Response, error)

Patch is a helper func for Do, setting the Method internally

func (*Client) Post

func (cl *Client) Post(c context.Context, url string, opts ...fetcher.RequestOption) (*fetcher.Response, error)

Post is a helper func for Do, setting the Method internally

func (*Client) Put

func (cl *Client) Put(c context.Context, url string, opts ...fetcher.RequestOption) (*fetcher.Response, error)

Put is a helper func for Do, setting the Method internally

func (*Client) UnmetExpectations

func (cl *Client) UnmetExpectations() []*ExpectedRequest

UnmetExpectations returns the slice of ExpectedRequests that were not met in execution

type ClientOption

type ClientOption func(c context.Context, cl *Client) error

ClientOption is a func to configure optional Client settings

func WithExpectationsInOrder

func WithExpectationsInOrder(inOrder bool) ClientOption

WithExpectationsInOrder sets the cl.withExpectationsInOrder value

func WithFetcherClientOptions

func WithFetcherClientOptions(opts ...fetcher.ClientOption) ClientOption

WithFetcherClientOptions sets the cl.withFetcherClientOptions value

type ExpectedRequest

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

ExpectedRequest contains the info for a Request to expect in execution

type ExpectedRequestOption

type ExpectedRequestOption func(c context.Context, expReq *ExpectedRequest) error

ExpectedRequestOption is a func to configure optional settings for an ExpectedRequest

func WithRequestOptions

func WithRequestOptions(opts ...fetcher.RequestOption) ExpectedRequestOption

WithRequestOptions adds all the given fetcher.RequestOptions to the requestOptions in the ExpectedRequest

func WithResponseBodyBytes

func WithResponseBodyBytes(b []byte) ExpectedRequestOption

WithResponseBodyBytes sets the responseBodyBytes in the ExpectedRequest

func WithResponseBodyReader

func WithResponseBodyReader(r io.Reader) ExpectedRequestOption

WithResponseBodyReader sets the responseBodyReader in the ExpectedRequest

func WithResponseError

func WithResponseError(err error) ExpectedRequestOption

WithResponseError sets the ResponseError in the ExpectedRequest

func WithResponseHeader

func WithResponseHeader(key, value string) ExpectedRequestOption

WithResponseHeader sets the key/value in the responseHeader in the ExpectedRequest

func WithResponseStatus

func WithResponseStatus(status string) ExpectedRequestOption

WithResponseStatus sets the responseStatus in the ExpectedRequest

func WithResponseStatusCode

func WithResponseStatusCode(code int) ExpectedRequestOption

WithResponseStatusCode sets the responseStatusCode in the ExpectedRequest

Jump to

Keyboard shortcuts

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