apitest

package
v0.0.0-...-1336f48 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeClient

type FakeClient struct {
	sync.Mutex
	// contains filtered or unexported fields
}

FakeClient is a fake api.Client meant for testing.

It allows stubbing out responses and records all requests sent.

Since the api.Client contract is very simple, it's not useful to use a real object in tests.

func NewFakeClient

func NewFakeClient(baseURLString string) *FakeClient

func (*FakeClient) Do

func (c *FakeClient) Do(req *http.Request) (*http.Response, error)

func (*FakeClient) GetRequests

func (c *FakeClient) GetRequests() []RequestCopy

GetRequests returns all requests made to the fake client.

func (*FakeClient) Send

func (c *FakeClient) Send(req *api.Request) (*http.Response, error)

func (*FakeClient) SetResponse

func (c *FakeClient) SetResponse(resp *TestResponse, err error)

SetResponse configures the client's response to all requests.

func (*FakeClient) WaitUntilRequestCount

func (c *FakeClient) WaitUntilRequestCount(
	t *testing.T,
	n int,
	timeout time.Duration,
)

WaitUntilRequestCount blocks until len(GetRequests()) >= n.

type RequestCopy

type RequestCopy struct {
	Method string
	URL    string
	Body   []byte
	Header http.Header
}

type TestResponse

type TestResponse struct {
	StatusCode int
}

TestResponse is an easy-to-use http.Response for tests.

Jump to

Keyboard shortcuts

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