testutil

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testutil provides testing utilities for the Dash0 CLI.

Index

Constants

View Source
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"
	FixtureDashboardsUnauthorized  = "dashboards/error_unauthorized.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"

	// Members fixtures
	FixtureMembersListSuccess  = "members/list_success.json"
	FixtureMembersListEmpty    = "members/list_empty.json"
	FixtureMembersUnauthorized = "members/error_unauthorized.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"

	// Notification channels fixtures
	FixtureNotificationChannelsListSuccess   = "notificationchannels/list_success.json"
	FixtureNotificationChannelsListEmpty     = "notificationchannels/list_empty.json"
	FixtureNotificationChannelsGetSuccess    = "notificationchannels/get_success.json"
	FixtureNotificationChannelsCreateSuccess = "notificationchannels/create_success.json"
	FixtureNotificationChannelsNotFound      = "notificationchannels/error_not_found.json"
	FixtureNotificationChannelsUnauthorized  = "notificationchannels/error_unauthorized.json"

	// Recording rules fixtures
	FixtureRecordingRulesListSuccess   = "recordingrules/list_success.json"
	FixtureRecordingRulesListEmpty     = "recordingrules/list_empty.json"
	FixtureRecordingRulesGetSuccess    = "recordingrules/get_success.json"
	FixtureRecordingRulesCreateSuccess = "recordingrules/create_success.json"
	FixtureRecordingRulesNotFound      = "recordingrules/error_not_found.json"

	// Teams fixtures
	FixtureTeamsListSuccess   = "teams/list_success.json"
	FixtureTeamsListEmpty     = "teams/list_empty.json"
	FixtureTeamsGetSuccess    = "teams/get_success.json"
	FixtureTeamsCreateSuccess = "teams/create_success.json"
	FixtureTeamsNotFound      = "teams/error_not_found.json"
	FixtureTeamsUnauthorized  = "teams/error_unauthorized.json"

	// Spam filters fixtures
	FixtureSpamFiltersListSuccess   = "spamfilters/list_success.json"
	FixtureSpamFiltersListEmpty     = "spamfilters/list_empty.json"
	FixtureSpamFiltersGetSuccess    = "spamfilters/get_success.json"
	FixtureSpamFiltersCreateSuccess = "spamfilters/create_success.json"
	FixtureSpamFiltersNotFound      = "spamfilters/error_not_found.json"
)

Fixture paths relative to the fixtures directory.

Variables

This section is empty.

Functions

func CaptureStderr added in v1.10.0

func CaptureStderr(t *testing.T, fn func()) string

CaptureStderr captures stderr during the execution of the given function. It returns the captured output as a string.

func CaptureStdout

func CaptureStdout(t *testing.T, fn func()) string

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

func RequireAuthHeader(r *http.Request) error

RequireAuthHeader is a validator that checks for the presence of an Authorization header.

func RequireHeaders added in v1.5.0

func RequireHeaders(r *http.Request) error

RequireHeaders is a validator that checks for both the Authorization and User-Agent headers.

func RequireUserAgentHeader added in v1.5.0

func RequireUserAgentHeader(r *http.Request) error

RequireUserAgentHeader is a validator that checks that the User-Agent header starts with "dash0-cli/".

func SetupTestEnv

func SetupTestEnv(t *testing.T)

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

type MockServer struct {
	*httptest.Server
	// contains filtered or unexported fields
}

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

func (m *MockServer) Reset()

Reset clears all recorded requests.

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) WithCheckRulesUpdate added in v1.7.1

func (m *MockServer) WithCheckRulesUpdate(fixture string) *MockServer

WithCheckRulesUpdate sets up the mock server to accept check rule updates.

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) WithRecordingRulesCreate added in v1.11.0

func (m *MockServer) WithRecordingRulesCreate(fixture string) *MockServer

WithRecordingRulesCreate sets up the mock server to accept recording rule creation.

func (*MockServer) WithRecordingRulesDelete added in v1.11.0

func (m *MockServer) WithRecordingRulesDelete() *MockServer

WithRecordingRulesDelete sets up the mock server to accept recording rule deletion.

func (*MockServer) WithRecordingRulesGet added in v1.11.0

func (m *MockServer) WithRecordingRulesGet(fixture string) *MockServer

WithRecordingRulesGet sets up the mock server to return a recording rule by ID.

func (*MockServer) WithRecordingRulesList added in v1.11.0

func (m *MockServer) WithRecordingRulesList(fixture string) *MockServer

WithRecordingRulesList sets up the mock server to return a list of recording rules.

func (*MockServer) WithRecordingRulesUpdate added in v1.11.0

func (m *MockServer) WithRecordingRulesUpdate(fixture string) *MockServer

WithRecordingRulesUpdate sets up the mock server to accept recording rule updates.

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) WithSyntheticChecksUpdate added in v1.7.1

func (m *MockServer) WithSyntheticChecksUpdate(fixture string) *MockServer

WithSyntheticChecksUpdate sets up the mock server to accept synthetic check updates.

func (*MockServer) WithUnauthorized

func (m *MockServer) WithUnauthorized(fixture string) *MockServer

WithUnauthorized sets up the mock server to return 401 Unauthorized.

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.

func (*MockServer) WithViewsUpdate added in v1.7.1

func (m *MockServer) WithViewsUpdate(fixture string) *MockServer

WithViewsUpdate sets up the mock server to accept view updates.

type RecordedRequest

type RecordedRequest struct {
	Method string
	Path   string
	Query  string
	Body   []byte
	Header http.Header
}

RecordedRequest stores information about a received request.

Jump to

Keyboard shortcuts

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