mocks

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2020 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockTransport

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

MockTransport implements http.RoundTripper, which fulfills single http requests issued by an http.Client. This implementation doesn't actually make the call, instead defering to the registered list of responders.

func (*MockTransport) RegisterResponder

func (m *MockTransport) RegisterResponder(method, url string, responder Responder)

RegisterResponder adds a new responder, associated with a given HTTP method and URL. When a request comes in that matches, the responder will be called and the response returned to the client.

func (*MockTransport) RoundTrip

func (m *MockTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip is required to implement http.MockTransport. Instead of fulfilling the given request, the internal list of responders is consulted to handle the request. If no responder is found an error is returned, which is the equivalent of a network error.

type Responder

type Responder func(*http.Request) (*http.Response, error)

Responders are callbacks that receive and http request and return a mocked response.

Jump to

Keyboard shortcuts

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