dash0test

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package dash0test provides testing utilities for the Dash0 API client.

Index

Constants

View Source
const (
	// TestAuthToken is a valid test auth token for use in tests.
	TestAuthToken = "auth_test_token"

	// TestDataset is a test dataset name for use in tests.
	TestDataset = "test-dataset"
)

Variables

This section is empty.

Functions

func MockServer

func MockServer(t *testing.T, method, path string, statusCode int, response interface{}) *httptest.Server

MockServer creates a test server that responds with the given data. It validates that requests match the expected method and path.

Example:

server := dash0test.MockServer(t, "GET", "/api/dashboards", http.StatusOK, []dash0.Dashboard{})
defer server.Close()

client, _ := dash0.NewClient(dash0.WithApiUrl(server.URL), dash0.WithAuthToken(dash0test.TestAuthToken))

func MockServerFunc

func MockServerFunc(handler http.HandlerFunc) *httptest.Server

MockServerFunc creates a test server with a custom handler function. Use this when you need more control over the response behavior.

Example:

server := dash0test.MockServerFunc(func(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("x-trace-id", "test-trace-id")
    w.WriteHeader(http.StatusOK)
    json.NewEncoder(w).Encode(myResponse)
})
defer server.Close()

Types

type MockClient

type MockClient struct {
	// Dashboards
	ListDashboardsFunc     func(ctx context.Context, dataset *string) ([]*dash0.DashboardApiListItem, error)
	GetDashboardFunc       func(ctx context.Context, originOrID string, dataset *string) (*dash0.DashboardDefinition, error)
	CreateDashboardFunc    func(ctx context.Context, dashboard *dash0.DashboardDefinition, dataset *string) (*dash0.DashboardDefinition, error)
	UpdateDashboardFunc    func(ctx context.Context, originOrID string, dashboard *dash0.DashboardDefinition, dataset *string) (*dash0.DashboardDefinition, error)
	DeleteDashboardFunc    func(ctx context.Context, originOrID string, dataset *string) error
	ListDashboardsIterFunc func(ctx context.Context, dataset *string) *dash0.Iter[dash0.DashboardApiListItem]

	// Check Rules
	ListCheckRulesFunc     func(ctx context.Context, dataset *string) ([]*dash0.PrometheusAlertRuleApiListItem, error)
	GetCheckRuleFunc       func(ctx context.Context, originOrID string, dataset *string) (*dash0.PrometheusAlertRule, error)
	CreateCheckRuleFunc    func(ctx context.Context, rule *dash0.PrometheusAlertRule, dataset *string) (*dash0.PrometheusAlertRule, error)
	UpdateCheckRuleFunc    func(ctx context.Context, originOrID string, rule *dash0.PrometheusAlertRule, dataset *string) (*dash0.PrometheusAlertRule, error)
	DeleteCheckRuleFunc    func(ctx context.Context, originOrID string, dataset *string) error
	ListCheckRulesIterFunc func(ctx context.Context, dataset *string) *dash0.Iter[dash0.PrometheusAlertRuleApiListItem]

	// Synthetic Checks
	ListSyntheticChecksFunc     func(ctx context.Context, dataset *string) ([]*dash0.SyntheticChecksApiListItem, error)
	GetSyntheticCheckFunc       func(ctx context.Context, originOrID string, dataset *string) (*dash0.SyntheticCheckDefinition, error)
	CreateSyntheticCheckFunc    func(ctx context.Context, check *dash0.SyntheticCheckDefinition, dataset *string) (*dash0.SyntheticCheckDefinition, error)
	UpdateSyntheticCheckFunc    func(ctx context.Context, originOrID string, check *dash0.SyntheticCheckDefinition, dataset *string) (*dash0.SyntheticCheckDefinition, error)
	DeleteSyntheticCheckFunc    func(ctx context.Context, originOrID string, dataset *string) error
	ListSyntheticChecksIterFunc func(ctx context.Context, dataset *string) *dash0.Iter[dash0.SyntheticChecksApiListItem]

	// Views
	ListViewsFunc     func(ctx context.Context, dataset *string) ([]*dash0.ViewApiListItem, error)
	GetViewFunc       func(ctx context.Context, originOrID string, dataset *string) (*dash0.ViewDefinition, error)
	CreateViewFunc    func(ctx context.Context, view *dash0.ViewDefinition, dataset *string) (*dash0.ViewDefinition, error)
	UpdateViewFunc    func(ctx context.Context, originOrID string, view *dash0.ViewDefinition, dataset *string) (*dash0.ViewDefinition, error)
	DeleteViewFunc    func(ctx context.Context, originOrID string, dataset *string) error
	ListViewsIterFunc func(ctx context.Context, dataset *string) *dash0.Iter[dash0.ViewApiListItem]

	// Sampling Rules
	ListSamplingRulesFunc     func(ctx context.Context, dataset *string) ([]*dash0.SamplingDefinition, error)
	GetSamplingRuleFunc       func(ctx context.Context, originOrID string, dataset *string) (*dash0.SamplingDefinition, error)
	CreateSamplingRuleFunc    func(ctx context.Context, rule *dash0.SamplingDefinition, dataset *string) (*dash0.SamplingDefinition, error)
	UpdateSamplingRuleFunc    func(ctx context.Context, originOrID string, rule *dash0.SamplingDefinition, dataset *string) (*dash0.SamplingDefinition, error)
	DeleteSamplingRuleFunc    func(ctx context.Context, originOrID string, dataset *string) error
	ListSamplingRulesIterFunc func(ctx context.Context, dataset *string) *dash0.Iter[dash0.SamplingDefinition]

	// Members
	ListMembersFunc     func(ctx context.Context) ([]*dash0.MemberDefinition, error)
	InviteMemberFunc    func(ctx context.Context, request *dash0.InviteMemberRequest) error
	DeleteMemberFunc    func(ctx context.Context, memberID string) error
	ListMembersIterFunc func(ctx context.Context) *dash0.Iter[dash0.MemberDefinition]

	// Teams
	ListTeamsFunc         func(ctx context.Context) ([]*dash0.TeamsListItem, error)
	CreateTeamFunc        func(ctx context.Context, team *dash0.TeamDefinition) (*dash0.TeamDefinition, error)
	GetTeamFunc           func(ctx context.Context, originOrID string) (*dash0.GetTeamResponse, error)
	DeleteTeamFunc        func(ctx context.Context, originOrID string) error
	UpdateTeamDisplayFunc func(ctx context.Context, originOrID string, display *dash0.TeamDisplay) error
	AddTeamMembersFunc    func(ctx context.Context, originOrID string, request *dash0.AddTeamMembersRequest) error
	RemoveTeamMemberFunc  func(ctx context.Context, originOrID string, memberID string) error
	ListTeamsIterFunc     func(ctx context.Context) *dash0.Iter[dash0.TeamsListItem]

	// Recording Rules
	ListRecordingRulesFunc     func(ctx context.Context, dataset *string) ([]*dash0.RecordingRule, error)
	GetRecordingRuleFunc       func(ctx context.Context, originOrID string, dataset *string) (*dash0.RecordingRule, error)
	CreateRecordingRuleFunc    func(ctx context.Context, rule *dash0.RecordingRule, dataset *string) (*dash0.RecordingRule, error)
	UpdateRecordingRuleFunc    func(ctx context.Context, originOrID string, rule *dash0.RecordingRule, dataset *string) (*dash0.RecordingRule, error)
	DeleteRecordingRuleFunc    func(ctx context.Context, originOrID string, dataset *string) error
	ListRecordingRulesIterFunc func(ctx context.Context, dataset *string) *dash0.Iter[dash0.RecordingRule]

	// Notification Channels
	ListNotificationChannelsFunc     func(ctx context.Context) ([]*dash0.NotificationChannelDefinition, error)
	GetNotificationChannelFunc       func(ctx context.Context, originOrID string) (*dash0.NotificationChannelDefinition, error)
	CreateNotificationChannelFunc    func(ctx context.Context, channel *dash0.NotificationChannelDefinition) (*dash0.NotificationChannelDefinition, error)
	UpdateNotificationChannelFunc    func(ctx context.Context, originOrID string, channel *dash0.NotificationChannelDefinition) (*dash0.NotificationChannelDefinition, error)
	DeleteNotificationChannelFunc    func(ctx context.Context, originOrID string) error
	ListNotificationChannelsIterFunc func(ctx context.Context) *dash0.Iter[dash0.NotificationChannelDefinition]

	// Spans
	GetSpansFunc     func(ctx context.Context, request *dash0.GetSpansRequest) (*dash0.GetSpansResponse, error)
	GetSpansIterFunc func(ctx context.Context, request *dash0.GetSpansRequest) *dash0.Iter[dash0.ResourceSpans]

	// Logs
	GetLogRecordsFunc     func(ctx context.Context, request *dash0.GetLogRecordsRequest) (*dash0.GetLogRecordsResponse, error)
	GetLogRecordsIterFunc func(ctx context.Context, request *dash0.GetLogRecordsRequest) *dash0.Iter[dash0.ResourceLogs]

	// Import
	ImportCheckRuleFunc      func(ctx context.Context, rule *dash0.PrometheusAlertRule, dataset *string) (*dash0.PrometheusAlertRule, error)
	ImportDashboardFunc      func(ctx context.Context, dashboard *dash0.DashboardDefinition, dataset *string) (*dash0.DashboardDefinition, error)
	ImportSyntheticCheckFunc func(ctx context.Context, check *dash0.SyntheticCheckDefinition, dataset *string) (*dash0.SyntheticCheckDefinition, error)
	ImportViewFunc           func(ctx context.Context, view *dash0.ViewDefinition, dataset *string) (*dash0.ViewDefinition, error)

	// OTLP
	SendLogsFunc    func(ctx context.Context, logs plog.Logs, dataset *string) error
	SendMetricsFunc func(ctx context.Context, metrics pmetric.Metrics, dataset *string) error
	SendTracesFunc  func(ctx context.Context, traces ptrace.Traces, dataset *string) error
	CloseFunc       func(ctx context.Context) error

	// Inner
	InnerFunc func() *dash0.ClientWithResponses
}

MockClient is a configurable mock implementation of dash0.Client. Set the function fields to customize behavior for each test.

Example:

mock := &dash0test.MockClient{
    ListDashboardsFunc: func(ctx context.Context, dataset *string) ([]*dash0.DashboardApiListItem, error) {
        return []*dash0.DashboardApiListItem{{Id: dash0.Ptr("test-id")}}, nil
    },
}
svc := NewMyService(mock) // accepts dash0.Client interface

func (*MockClient) AddTeamMembers added in v1.4.0

func (m *MockClient) AddTeamMembers(ctx context.Context, originOrID string, request *dash0.AddTeamMembersRequest) error

func (*MockClient) Close added in v1.2.0

func (m *MockClient) Close(ctx context.Context) error

func (*MockClient) CreateCheckRule

func (m *MockClient) CreateCheckRule(ctx context.Context, rule *dash0.PrometheusAlertRule, dataset *string) (*dash0.PrometheusAlertRule, error)

func (*MockClient) CreateDashboard

func (m *MockClient) CreateDashboard(ctx context.Context, dashboard *dash0.DashboardDefinition, dataset *string) (*dash0.DashboardDefinition, error)

func (*MockClient) CreateNotificationChannel added in v1.9.0

func (*MockClient) CreateRecordingRule added in v1.10.0

func (m *MockClient) CreateRecordingRule(ctx context.Context, rule *dash0.RecordingRule, dataset *string) (*dash0.RecordingRule, error)

func (*MockClient) CreateSamplingRule added in v1.1.0

func (m *MockClient) CreateSamplingRule(ctx context.Context, rule *dash0.SamplingDefinition, dataset *string) (*dash0.SamplingDefinition, error)

func (*MockClient) CreateSyntheticCheck

func (m *MockClient) CreateSyntheticCheck(ctx context.Context, check *dash0.SyntheticCheckDefinition, dataset *string) (*dash0.SyntheticCheckDefinition, error)

func (*MockClient) CreateTeam added in v1.4.0

func (m *MockClient) CreateTeam(ctx context.Context, team *dash0.TeamDefinition) (*dash0.TeamDefinition, error)

func (*MockClient) CreateView

func (m *MockClient) CreateView(ctx context.Context, view *dash0.ViewDefinition, dataset *string) (*dash0.ViewDefinition, error)

func (*MockClient) DeleteCheckRule

func (m *MockClient) DeleteCheckRule(ctx context.Context, originOrID string, dataset *string) error

func (*MockClient) DeleteDashboard

func (m *MockClient) DeleteDashboard(ctx context.Context, originOrID string, dataset *string) error

func (*MockClient) DeleteMember added in v1.4.0

func (m *MockClient) DeleteMember(ctx context.Context, memberID string) error

func (*MockClient) DeleteNotificationChannel added in v1.9.0

func (m *MockClient) DeleteNotificationChannel(ctx context.Context, originOrID string) error

func (*MockClient) DeleteRecordingRule added in v1.10.0

func (m *MockClient) DeleteRecordingRule(ctx context.Context, originOrID string, dataset *string) error

func (*MockClient) DeleteSamplingRule added in v1.1.0

func (m *MockClient) DeleteSamplingRule(ctx context.Context, originOrID string, dataset *string) error

func (*MockClient) DeleteSyntheticCheck

func (m *MockClient) DeleteSyntheticCheck(ctx context.Context, originOrID string, dataset *string) error

func (*MockClient) DeleteTeam added in v1.4.0

func (m *MockClient) DeleteTeam(ctx context.Context, originOrID string) error

func (*MockClient) DeleteView

func (m *MockClient) DeleteView(ctx context.Context, originOrID string, dataset *string) error

func (*MockClient) GetCheckRule

func (m *MockClient) GetCheckRule(ctx context.Context, originOrID string, dataset *string) (*dash0.PrometheusAlertRule, error)

func (*MockClient) GetDashboard

func (m *MockClient) GetDashboard(ctx context.Context, originOrID string, dataset *string) (*dash0.DashboardDefinition, error)

func (*MockClient) GetLogRecords

func (*MockClient) GetLogRecordsIter

func (m *MockClient) GetLogRecordsIter(ctx context.Context, request *dash0.GetLogRecordsRequest) *dash0.Iter[dash0.ResourceLogs]

func (*MockClient) GetNotificationChannel added in v1.9.0

func (m *MockClient) GetNotificationChannel(ctx context.Context, originOrID string) (*dash0.NotificationChannelDefinition, error)

func (*MockClient) GetRecordingRule added in v1.10.0

func (m *MockClient) GetRecordingRule(ctx context.Context, originOrID string, dataset *string) (*dash0.RecordingRule, error)

func (*MockClient) GetSamplingRule added in v1.1.0

func (m *MockClient) GetSamplingRule(ctx context.Context, originOrID string, dataset *string) (*dash0.SamplingDefinition, error)

func (*MockClient) GetSpans

func (m *MockClient) GetSpans(ctx context.Context, request *dash0.GetSpansRequest) (*dash0.GetSpansResponse, error)

func (*MockClient) GetSpansIter

func (m *MockClient) GetSpansIter(ctx context.Context, request *dash0.GetSpansRequest) *dash0.Iter[dash0.ResourceSpans]

func (*MockClient) GetSyntheticCheck

func (m *MockClient) GetSyntheticCheck(ctx context.Context, originOrID string, dataset *string) (*dash0.SyntheticCheckDefinition, error)

func (*MockClient) GetTeam added in v1.4.0

func (m *MockClient) GetTeam(ctx context.Context, originOrID string) (*dash0.GetTeamResponse, error)

func (*MockClient) GetView

func (m *MockClient) GetView(ctx context.Context, originOrID string, dataset *string) (*dash0.ViewDefinition, error)

func (*MockClient) ImportCheckRule

func (m *MockClient) ImportCheckRule(ctx context.Context, rule *dash0.PrometheusAlertRule, dataset *string) (*dash0.PrometheusAlertRule, error)

func (*MockClient) ImportDashboard

func (m *MockClient) ImportDashboard(ctx context.Context, dashboard *dash0.DashboardDefinition, dataset *string) (*dash0.DashboardDefinition, error)

func (*MockClient) ImportSyntheticCheck

func (m *MockClient) ImportSyntheticCheck(ctx context.Context, check *dash0.SyntheticCheckDefinition, dataset *string) (*dash0.SyntheticCheckDefinition, error)

func (*MockClient) ImportView

func (m *MockClient) ImportView(ctx context.Context, view *dash0.ViewDefinition, dataset *string) (*dash0.ViewDefinition, error)

func (*MockClient) Inner

func (m *MockClient) Inner() *dash0.ClientWithResponses

func (*MockClient) InviteMember added in v1.4.0

func (m *MockClient) InviteMember(ctx context.Context, request *dash0.InviteMemberRequest) error

func (*MockClient) ListCheckRules

func (m *MockClient) ListCheckRules(ctx context.Context, dataset *string) ([]*dash0.PrometheusAlertRuleApiListItem, error)

func (*MockClient) ListCheckRulesIter

func (m *MockClient) ListCheckRulesIter(ctx context.Context, dataset *string) *dash0.Iter[dash0.PrometheusAlertRuleApiListItem]

func (*MockClient) ListDashboards

func (m *MockClient) ListDashboards(ctx context.Context, dataset *string) ([]*dash0.DashboardApiListItem, error)

func (*MockClient) ListDashboardsIter

func (m *MockClient) ListDashboardsIter(ctx context.Context, dataset *string) *dash0.Iter[dash0.DashboardApiListItem]

func (*MockClient) ListMembers added in v1.4.0

func (m *MockClient) ListMembers(ctx context.Context) ([]*dash0.MemberDefinition, error)

func (*MockClient) ListMembersIter added in v1.4.0

func (m *MockClient) ListMembersIter(ctx context.Context) *dash0.Iter[dash0.MemberDefinition]

func (*MockClient) ListNotificationChannels added in v1.9.0

func (m *MockClient) ListNotificationChannels(ctx context.Context) ([]*dash0.NotificationChannelDefinition, error)

func (*MockClient) ListNotificationChannelsIter added in v1.9.0

func (m *MockClient) ListNotificationChannelsIter(ctx context.Context) *dash0.Iter[dash0.NotificationChannelDefinition]

func (*MockClient) ListRecordingRules added in v1.10.0

func (m *MockClient) ListRecordingRules(ctx context.Context, dataset *string) ([]*dash0.RecordingRule, error)

func (*MockClient) ListRecordingRulesIter added in v1.10.0

func (m *MockClient) ListRecordingRulesIter(ctx context.Context, dataset *string) *dash0.Iter[dash0.RecordingRule]

func (*MockClient) ListSamplingRules added in v1.1.0

func (m *MockClient) ListSamplingRules(ctx context.Context, dataset *string) ([]*dash0.SamplingDefinition, error)

func (*MockClient) ListSamplingRulesIter added in v1.1.0

func (m *MockClient) ListSamplingRulesIter(ctx context.Context, dataset *string) *dash0.Iter[dash0.SamplingDefinition]

func (*MockClient) ListSyntheticChecks

func (m *MockClient) ListSyntheticChecks(ctx context.Context, dataset *string) ([]*dash0.SyntheticChecksApiListItem, error)

func (*MockClient) ListSyntheticChecksIter

func (m *MockClient) ListSyntheticChecksIter(ctx context.Context, dataset *string) *dash0.Iter[dash0.SyntheticChecksApiListItem]

func (*MockClient) ListTeams added in v1.4.0

func (m *MockClient) ListTeams(ctx context.Context) ([]*dash0.TeamsListItem, error)

func (*MockClient) ListTeamsIter added in v1.4.0

func (m *MockClient) ListTeamsIter(ctx context.Context) *dash0.Iter[dash0.TeamsListItem]

func (*MockClient) ListViews

func (m *MockClient) ListViews(ctx context.Context, dataset *string) ([]*dash0.ViewApiListItem, error)

func (*MockClient) ListViewsIter

func (m *MockClient) ListViewsIter(ctx context.Context, dataset *string) *dash0.Iter[dash0.ViewApiListItem]

func (*MockClient) RemoveTeamMember added in v1.4.0

func (m *MockClient) RemoveTeamMember(ctx context.Context, originOrID string, memberID string) error

func (*MockClient) SendLogs added in v1.2.0

func (m *MockClient) SendLogs(ctx context.Context, logs plog.Logs, dataset *string) error

func (*MockClient) SendMetrics added in v1.2.0

func (m *MockClient) SendMetrics(ctx context.Context, metrics pmetric.Metrics, dataset *string) error

func (*MockClient) SendTraces added in v1.2.0

func (m *MockClient) SendTraces(ctx context.Context, traces ptrace.Traces, dataset *string) error

func (*MockClient) UpdateCheckRule

func (m *MockClient) UpdateCheckRule(ctx context.Context, originOrID string, rule *dash0.PrometheusAlertRule, dataset *string) (*dash0.PrometheusAlertRule, error)

func (*MockClient) UpdateDashboard

func (m *MockClient) UpdateDashboard(ctx context.Context, originOrID string, dashboard *dash0.DashboardDefinition, dataset *string) (*dash0.DashboardDefinition, error)

func (*MockClient) UpdateNotificationChannel added in v1.9.0

func (m *MockClient) UpdateNotificationChannel(ctx context.Context, originOrID string, channel *dash0.NotificationChannelDefinition) (*dash0.NotificationChannelDefinition, error)

func (*MockClient) UpdateRecordingRule added in v1.10.0

func (m *MockClient) UpdateRecordingRule(ctx context.Context, originOrID string, rule *dash0.RecordingRule, dataset *string) (*dash0.RecordingRule, error)

func (*MockClient) UpdateSamplingRule added in v1.1.0

func (m *MockClient) UpdateSamplingRule(ctx context.Context, originOrID string, rule *dash0.SamplingDefinition, dataset *string) (*dash0.SamplingDefinition, error)

func (*MockClient) UpdateSyntheticCheck

func (m *MockClient) UpdateSyntheticCheck(ctx context.Context, originOrID string, check *dash0.SyntheticCheckDefinition, dataset *string) (*dash0.SyntheticCheckDefinition, error)

func (*MockClient) UpdateTeamDisplay added in v1.4.0

func (m *MockClient) UpdateTeamDisplay(ctx context.Context, originOrID string, display *dash0.TeamDisplay) error

func (*MockClient) UpdateView

func (m *MockClient) UpdateView(ctx context.Context, originOrID string, view *dash0.ViewDefinition, dataset *string) (*dash0.ViewDefinition, error)

Jump to

Keyboard shortcuts

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