Documentation
¶
Index ¶
- func MockResponse(code int, body []byte, contentType string) *http.Response
- func ReadString(r io.Reader) string
- type MockHttpClient
- func (m *MockHttpClient) AddError(method, url string, err error) *MockHttpClient
- func (m *MockHttpClient) AddLiteralByteResponse(method, url string, wholeResponse []byte) *MockHttpClient
- func (m *MockHttpClient) AddLiteralResponse(method, url string, wholeResponse string) *MockHttpClient
- func (m *MockHttpClient) AddOutcome(method, url string, outcome Outcome) *MockHttpClient
- func (m *MockHttpClient) AddResponse(method, url string, response *http.Response) *MockHttpClient
- func (m *MockHttpClient) CapturedBody(i int) string
- func (m *MockHttpClient) Do(req *http.Request) (*http.Response, error)
- func (m *MockHttpClient) RemainingOutcomes() (n int)
- func (m *MockHttpClient) Reset()
- type Outcome
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MockResponse ¶
MockResponse builds a http.Response.
func ReadString ¶
Types ¶
type MockHttpClient ¶
type MockHttpClient struct {
CapturedRequests []*http.Request
// contains filtered or unexported fields
}
MockHttpClient is a HttpClient that holds some stubbed outcomes.
func New ¶
func New(t TestingT) *MockHttpClient
func (*MockHttpClient) AddError ¶
func (m *MockHttpClient) AddError(method, url string, err error) *MockHttpClient
func (*MockHttpClient) AddLiteralByteResponse ¶
func (m *MockHttpClient) AddLiteralByteResponse(method, url string, wholeResponse []byte) *MockHttpClient
func (*MockHttpClient) AddLiteralResponse ¶
func (m *MockHttpClient) AddLiteralResponse(method, url string, wholeResponse string) *MockHttpClient
AddLiteralResponse adds an expected outcome that has a literal HTTP response as provided. An example might be
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 18
{"A":"foo","B":7}
func (*MockHttpClient) AddOutcome ¶
func (m *MockHttpClient) AddOutcome(method, url string, outcome Outcome) *MockHttpClient
AddOutcome adds an outcome directly.
func (*MockHttpClient) AddResponse ¶
func (m *MockHttpClient) AddResponse(method, url string, response *http.Response) *MockHttpClient
AddResponse adds an expected outcome with a response or an error. If the error is not nil, the response will be ignored (so it should be nil).
func (*MockHttpClient) CapturedBody ¶
func (m *MockHttpClient) CapturedBody(i int) string
func (*MockHttpClient) RemainingOutcomes ¶
func (m *MockHttpClient) RemainingOutcomes() (n int)
func (*MockHttpClient) Reset ¶
func (m *MockHttpClient) Reset()
Click to show internal directories.
Click to hide internal directories.