testhttpclient

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockResponse

func MockResponse(code int, body []byte, contentType string) *http.Response

MockResponse builds a http.Response.

func ReadString

func ReadString(r io.Reader) string

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) Do

func (m *MockHttpClient) Do(req *http.Request) (*http.Response, error)

func (*MockHttpClient) RemainingOutcomes

func (m *MockHttpClient) RemainingOutcomes() (n int)

func (*MockHttpClient) Reset

func (m *MockHttpClient) Reset()

func (*MockHttpClient) RoundTrip added in v0.0.5

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

type Outcome

type Outcome struct {
	Response *http.Response
	Err      error
}

Outcome defines a matching rule for an expected HTTP request outcome.

type TestingT

type TestingT interface {
	Fatalf(format string, args ...interface{})
	Helper()
}

TestingT is a simple *testing.T interface wrapper

Jump to

Keyboard shortcuts

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