httpmock

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 License: CC0-1.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockClient

func NewMockClient(r ...*Response) *http.Client

NewMockClient returns an *http.Client that uses a mocked transport to avoid real http calls. The mocked transport is able to handle multiple responses.

Types

type MockRoundTripper

type MockRoundTripper struct {
	Responses []*Response
	// contains filtered or unexported fields
}

MockRoundTripper implements http.RoundTripper and returns a pair of an http.Response and error when the RoundTrip method is invoked.

func NewMockRoundTripper

func NewMockRoundTripper(r ...*Response) *MockRoundTripper

NewMockRoundTripper initializes a new RoundTripper with the given list of Response.

func (*MockRoundTripper) RoundTrip

func (mock *MockRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip returns a pre-defined response and error based on the mocks provided by the user during the initialisation of MockRoundTripper.

type Response

type Response struct {
	Response *http.Response
	Error    error
}

Response Wraps the response of the RoundTrip.

func NewMockResponse

func NewMockResponse(resp *http.Response, err error) *Response

NewMockResponse returns a Response reference initialized with the given http.Response and the error.

Jump to

Keyboard shortcuts

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