Documentation
¶
Overview ¶
Package testutil provides testing utilities for the Dash0 CLI.
Index ¶
- Constants
- func CaptureStdout(t *testing.T, fn func()) string
- func FixturesDir() string
- func RequireAuthHeader(r *http.Request) error
- func SetupTestEnv(t *testing.T)
- type MockResponse
- type MockServer
- func (m *MockServer) LastRequest() *RecordedRequest
- func (m *MockServer) On(method, path string, resp MockResponse) *MockServer
- func (m *MockServer) OnDefault(handler http.HandlerFunc) *MockServer
- func (m *MockServer) OnPattern(method string, pattern *regexp.Regexp, resp MockResponse) *MockServer
- func (m *MockServer) Requests() []RecordedRequest
- func (m *MockServer) Reset()
- func (m *MockServer) WithCheckRuleImport(fixture string) *MockServer
- func (m *MockServer) WithCheckRulesCreate(fixture string) *MockServer
- func (m *MockServer) WithCheckRulesDelete() *MockServer
- func (m *MockServer) WithCheckRulesGet(fixture string) *MockServer
- func (m *MockServer) WithCheckRulesList(fixture string) *MockServer
- func (m *MockServer) WithDashboardImport(fixture string) *MockServer
- func (m *MockServer) WithDashboardsCreate(fixture string) *MockServer
- func (m *MockServer) WithDashboardsDelete() *MockServer
- func (m *MockServer) WithDashboardsGet(fixture string) *MockServer
- func (m *MockServer) WithDashboardsList(fixture string) *MockServer
- func (m *MockServer) WithDashboardsUpdate(fixture string) *MockServer
- func (m *MockServer) WithNotFound(fixture string) *MockServer
- func (m *MockServer) WithSyntheticCheckImport(fixture string) *MockServer
- func (m *MockServer) WithSyntheticChecksCreate(fixture string) *MockServer
- func (m *MockServer) WithSyntheticChecksDelete() *MockServer
- func (m *MockServer) WithSyntheticChecksGet(fixture string) *MockServer
- func (m *MockServer) WithSyntheticChecksList(fixture string) *MockServer
- func (m *MockServer) WithUnauthorized(fixture string) *MockServer
- func (m *MockServer) WithViewImport(fixture string) *MockServer
- func (m *MockServer) WithViewsCreate(fixture string) *MockServer
- func (m *MockServer) WithViewsDelete() *MockServer
- func (m *MockServer) WithViewsGet(fixture string) *MockServer
- func (m *MockServer) WithViewsList(fixture string) *MockServer
- type RecordedRequest
Constants ¶
const ( // Dashboards fixtures FixtureDashboardsListSuccess = "dashboards/list_success.json" FixtureDashboardsListEmpty = "dashboards/list_empty.json" FixtureDashboardsGetSuccess = "dashboards/get_success.json" FixtureDashboardsImportSuccess = "dashboards/import_success.json" FixtureDashboardsNotFound = "dashboards/error_not_found.json" // Check rules fixtures FixtureCheckRulesListSuccess = "checkrules/list_success.json" FixtureCheckRulesListEmpty = "checkrules/list_empty.json" FixtureCheckRulesGetSuccess = "checkrules/get_success.json" FixtureCheckRulesImportSuccess = "checkrules/import_success.json" FixtureCheckRulesNotFound = "checkrules/error_not_found.json" // Views fixtures FixtureViewsListSuccess = "views/list_success.json" FixtureViewsListEmpty = "views/list_empty.json" FixtureViewsGetSuccess = "views/get_success.json" FixtureViewsImportSuccess = "views/import_success.json" FixtureViewsNotFound = "views/error_not_found.json" // Logs fixtures FixtureLogsQuerySuccess = "logs/query_success.json" FixtureLogsQueryEmpty = "logs/query_empty.json" // Spans fixtures FixtureSpansQuerySuccess = "spans/query_success.json" FixtureSpansQueryEmpty = "spans/query_empty.json" // Traces fixtures FixtureTracesGetSuccess = "traces/get_success.json" FixtureTracesGetWithLinks = "traces/get_with_links.json" // Synthetic checks fixtures FixtureSyntheticChecksListSuccess = "syntheticchecks/list_success.json" FixtureSyntheticChecksListEmpty = "syntheticchecks/list_empty.json" FixtureSyntheticChecksGetSuccess = "syntheticchecks/get_success.json" FixtureSyntheticChecksImportSuccess = "syntheticchecks/import_success.json" FixtureSyntheticChecksNotFound = "syntheticchecks/error_not_found.json" )
Fixture paths relative to the fixtures directory.
Variables ¶
This section is empty.
Functions ¶
func CaptureStdout ¶
CaptureStdout captures stdout during the execution of the given function. It returns the captured output as a string.
func FixturesDir ¶
func FixturesDir() string
FixturesDir returns the absolute path to the fixtures directory.
func RequireAuthHeader ¶
RequireAuthHeader is a validator that checks for the presence of an Authorization header.
func SetupTestEnv ¶
SetupTestEnv sets environment variables for testing and returns a cleanup function.
Types ¶
type MockResponse ¶
type MockResponse struct {
// StatusCode is the HTTP status code to return.
StatusCode int
// BodyFile is the path to a fixture file containing the response body.
// If empty, Body is used instead.
BodyFile string
// Body is the response body to return if BodyFile is not set.
Body interface{}
// Validator is an optional function to validate the incoming request.
// If it returns an error, the mock server returns a 400 Bad Request.
Validator func(r *http.Request) error
}
MockResponse defines how the mock server should respond to a request.
type MockServer ¶
MockServer is a test HTTP server that serves responses from fixtures.
func NewMockServer ¶
func NewMockServer(t *testing.T, fixturesDir string) *MockServer
NewMockServer creates a new mock server for testing. The fixturesDir parameter specifies the base directory for fixture files.
func (*MockServer) LastRequest ¶
func (m *MockServer) LastRequest() *RecordedRequest
LastRequest returns the most recent request, or nil if no requests were made.
func (*MockServer) On ¶
func (m *MockServer) On(method, path string, resp MockResponse) *MockServer
On registers a mock response for a specific method and path.
func (*MockServer) OnDefault ¶
func (m *MockServer) OnDefault(handler http.HandlerFunc) *MockServer
OnDefault sets a default handler for unmatched requests.
func (*MockServer) OnPattern ¶
func (m *MockServer) OnPattern(method string, pattern *regexp.Regexp, resp MockResponse) *MockServer
OnPattern registers a mock response for requests matching a regex pattern.
func (*MockServer) Requests ¶
func (m *MockServer) Requests() []RecordedRequest
Requests returns all recorded requests.
func (*MockServer) WithCheckRuleImport ¶
func (m *MockServer) WithCheckRuleImport(fixture string) *MockServer
WithCheckRuleImport sets up the mock server to accept check rule imports.
func (*MockServer) WithCheckRulesCreate ¶
func (m *MockServer) WithCheckRulesCreate(fixture string) *MockServer
WithCheckRulesCreate sets up the mock server to accept check rule creation.
func (*MockServer) WithCheckRulesDelete ¶
func (m *MockServer) WithCheckRulesDelete() *MockServer
WithCheckRulesDelete sets up the mock server to accept check rule deletion.
func (*MockServer) WithCheckRulesGet ¶
func (m *MockServer) WithCheckRulesGet(fixture string) *MockServer
WithCheckRulesGet sets up the mock server to return a check rule by ID.
func (*MockServer) WithCheckRulesList ¶
func (m *MockServer) WithCheckRulesList(fixture string) *MockServer
WithCheckRulesList sets up the mock server to return a list of check rules.
func (*MockServer) WithDashboardImport ¶
func (m *MockServer) WithDashboardImport(fixture string) *MockServer
WithDashboardImport sets up the mock server to accept dashboard imports.
func (*MockServer) WithDashboardsCreate ¶
func (m *MockServer) WithDashboardsCreate(fixture string) *MockServer
WithDashboardsCreate sets up the mock server to accept dashboard creation.
func (*MockServer) WithDashboardsDelete ¶
func (m *MockServer) WithDashboardsDelete() *MockServer
WithDashboardsDelete sets up the mock server to accept dashboard deletion.
func (*MockServer) WithDashboardsGet ¶
func (m *MockServer) WithDashboardsGet(fixture string) *MockServer
WithDashboardsGet sets up the mock server to return a dashboard by ID.
func (*MockServer) WithDashboardsList ¶
func (m *MockServer) WithDashboardsList(fixture string) *MockServer
WithDashboardsList sets up the mock server to return a list of dashboards.
func (*MockServer) WithDashboardsUpdate ¶
func (m *MockServer) WithDashboardsUpdate(fixture string) *MockServer
WithDashboardsUpdate sets up the mock server to accept dashboard updates.
func (*MockServer) WithNotFound ¶
func (m *MockServer) WithNotFound(fixture string) *MockServer
WithNotFound sets up any unmatched route to return 404.
func (*MockServer) WithSyntheticCheckImport ¶
func (m *MockServer) WithSyntheticCheckImport(fixture string) *MockServer
WithSyntheticCheckImport sets up the mock server to accept synthetic check imports.
func (*MockServer) WithSyntheticChecksCreate ¶
func (m *MockServer) WithSyntheticChecksCreate(fixture string) *MockServer
WithSyntheticChecksCreate sets up the mock server to accept synthetic check creation.
func (*MockServer) WithSyntheticChecksDelete ¶
func (m *MockServer) WithSyntheticChecksDelete() *MockServer
WithSyntheticChecksDelete sets up the mock server to accept synthetic check deletion.
func (*MockServer) WithSyntheticChecksGet ¶
func (m *MockServer) WithSyntheticChecksGet(fixture string) *MockServer
WithSyntheticChecksGet sets up the mock server to return a synthetic check by ID.
func (*MockServer) WithSyntheticChecksList ¶
func (m *MockServer) WithSyntheticChecksList(fixture string) *MockServer
WithSyntheticChecksList sets up the mock server to return a list of synthetic checks.
func (*MockServer) WithUnauthorized ¶
func (m *MockServer) WithUnauthorized(fixture string) *MockServer
WithUnauthorized sets up the mock server to return 401 Unauthorized.
func (*MockServer) WithViewImport ¶
func (m *MockServer) WithViewImport(fixture string) *MockServer
WithViewImport sets up the mock server to accept view imports.
func (*MockServer) WithViewsCreate ¶
func (m *MockServer) WithViewsCreate(fixture string) *MockServer
WithViewsCreate sets up the mock server to accept view creation.
func (*MockServer) WithViewsDelete ¶
func (m *MockServer) WithViewsDelete() *MockServer
WithViewsDelete sets up the mock server to accept view deletion.
func (*MockServer) WithViewsGet ¶
func (m *MockServer) WithViewsGet(fixture string) *MockServer
WithViewsGet sets up the mock server to return a view by ID.
func (*MockServer) WithViewsList ¶
func (m *MockServer) WithViewsList(fixture string) *MockServer
WithViewsList sets up the mock server to return a list of views.