Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultMockTransport = &MockTransport{}
The global default RoundTripper for all http requests.
Functions ¶
func Activate ¶
func Activate(failNoResponder bool)
Activate replaces the `Transport` on the `http.DefaultClient` with our `DefaultMockTransport`.
func Deactivate ¶
func Deactivate()
Deactivate replaces our `DefaultMockTransport` with the `http.DefaultTransport`.
func NewTestServer ¶
Start a new Server with status OK, caller should call Close when finished
func NewTestServerWithBody ¶
func RegisterResponder ¶
Add a responder to `DefaultMockTransport`.
Types ¶
type MockTransport ¶
type MockTransport struct { FailNoResponder bool // contains filtered or unexported fields }
MockTransport implements http.RoundTripper. The implementation doesn't make the call, instead defering to the registered list of responders. Return Error if no responder is found when FailNoResponder = true
func (*MockTransport) RegisterResponder ¶
func (m *MockTransport) RegisterResponder(method, url string, responder Responder)
Add a new responder, associated with a given HTTP method and URL. When a request matches, the responder will be called and the response returned.
type Responder ¶
Responders are callbacks that receive http request and return a mocked response.
func CreateResponder ¶
Create a responder with protocol version "HTTP/1.0" and a mocked response in JSON