Documentation
¶
Overview ¶
Package testutils provides testing utilities for the Glean CLI, including mock HTTP transports for injecting test responses into the SDK.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetupTestConfig ¶
SetupTestConfig creates a test configuration and returns a cleanup function
Types ¶
type Fixtures ¶
type Fixtures struct {
// contains filtered or unexported fields
}
Fixtures provides a way to load test fixtures from files
func NewFixtures ¶
NewFixtures creates a new Fixtures instance with the given fixture files. The paths should be relative to the test file's location.
func (*Fixtures) LoadAsStream ¶
LoadAsStream returns the contents of a fixture file as a stream of JSON objects. This is useful for API responses that are streamed as newline-delimited JSON. If the file contains a single JSON object, it will be converted to a stream format. If the file contains multiple JSON objects (one per line), they will be preserved.
func (*Fixtures) LoadAsText ¶
LoadAsText returns the contents of a fixture file as plain text
func (*Fixtures) WithBasePath ¶
WithBasePath sets a custom base path for fixture files
type MockTransport ¶
type MockTransport struct {
// Body is returned for every request
Body []byte
// Err is returned instead of a response when non-nil
Err error
// StatusCode defaults to 200 when zero
StatusCode int
// ContentType defaults to "application/json" when empty
ContentType string
// Requests records all requests received for inspection
Requests []*http.Request
}
MockTransport implements http.RoundTripper (the Do method expected by glean.HTTPClient). It returns a predefined response body for every request, making it easy to test command output without making real network calls.
func SetupMockClient ¶
func SetupMockClient(body []byte, err error) (*MockTransport, func())
SetupMockClient injects a MockTransport into the SDK client factory and returns the mock plus a cleanup function that restores the original factory.
func SetupTestWithResponse ¶
func SetupTestWithResponse(t *testing.T, response []byte) (*MockTransport, func())
SetupTestWithResponse sets up both config and mock transport for testing.