Documentation
¶
Overview ¶
Package testutil provides testing utilities for the QuickBooks Online SDK.
Index ¶
- func LoadFixture(t *testing.T, name string) []byte
- func LoadFixtureFrom(t *testing.T, baseDir, name string) []byte
- func LoadJSONFixture(t *testing.T, name string, v any)
- func MustMarshalJSON(t *testing.T, v any) []byte
- func MustMarshalJSONIndent(t *testing.T, v any) []byte
- func MustReadFile(t *testing.T, path string) []byte
- func TempDir(t *testing.T) string
- func WriteFile(t *testing.T, dir, name string, data []byte) string
- type MockResponse
- type MockServer
- func (ms *MockServer) ClearRequests()
- func (ms *MockServer) LastRequest() *RecordedRequest
- func (ms *MockServer) Register(method, path string, resp MockResponse)
- func (ms *MockServer) RegisterJSON(method, path string, status int, body any)
- func (ms *MockServer) RequestCount() int
- func (ms *MockServer) Requests() []RecordedRequest
- func (ms *MockServer) Reset()
- func (ms *MockServer) SetDefaultResponse(resp MockResponse)
- func (ms *MockServer) URL() string
- type RecordedRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadFixture ¶
LoadFixture loads a fixture file from the testdata directory. The path should be relative to the testdata directory.
func LoadFixtureFrom ¶
LoadFixtureFrom loads a fixture file from a specified base directory.
func LoadJSONFixture ¶
LoadJSONFixture loads a JSON fixture and unmarshals it into the provided value.
func MustMarshalJSON ¶
MustMarshalJSON marshals a value to JSON, failing the test on error.
func MustMarshalJSONIndent ¶
MustMarshalJSONIndent marshals a value to indented JSON, failing the test on error.
func MustReadFile ¶
MustReadFile reads a file, failing the test on error.
Types ¶
type MockResponse ¶
type MockResponse struct {
// Status is the HTTP status code.
Status int
// Body is the response body.
Body string
// BodyJSON is the response body as a Go value (will be marshaled to JSON).
// If set, Body is ignored.
BodyJSON any
// Headers are additional response headers.
Headers map[string]string
// ContentType is the Content-Type header (defaults to "application/json").
ContentType string
}
MockResponse represents a mock HTTP response.
type MockServer ¶
type MockServer struct {
// Server is the underlying httptest.Server.
Server *httptest.Server
// contains filtered or unexported fields
}
MockServer is a mock HTTP server for testing.
func NewMockServer ¶
func NewMockServer(t *testing.T) *MockServer
NewMockServer creates a new mock server and registers cleanup with t.Cleanup.
func (*MockServer) ClearRequests ¶
func (ms *MockServer) ClearRequests()
ClearRequests clears recorded requests but keeps registered responses.
func (*MockServer) LastRequest ¶
func (ms *MockServer) LastRequest() *RecordedRequest
LastRequest returns the most recent request, or nil if no requests were made.
func (*MockServer) Register ¶
func (ms *MockServer) Register(method, path string, resp MockResponse)
Register registers a mock response for a given method and path.
func (*MockServer) RegisterJSON ¶
func (ms *MockServer) RegisterJSON(method, path string, status int, body any)
RegisterJSON registers a JSON response for a given method and path.
func (*MockServer) RequestCount ¶
func (ms *MockServer) RequestCount() int
RequestCount returns the number of requests made to the server.
func (*MockServer) Requests ¶
func (ms *MockServer) Requests() []RecordedRequest
Requests returns all recorded requests.
func (*MockServer) Reset ¶
func (ms *MockServer) Reset()
Reset clears all registered responses and recorded requests.
func (*MockServer) SetDefaultResponse ¶
func (ms *MockServer) SetDefaultResponse(resp MockResponse)
SetDefaultResponse sets the default response for unregistered endpoints.
type RecordedRequest ¶
type RecordedRequest struct {
// Method is the HTTP method.
Method string
// Path is the URL path.
Path string
// Query is the raw query string.
Query string
// Headers are the request headers.
Headers http.Header
// Body is the request body.
Body []byte
}
RecordedRequest represents a request that was made to the mock server.