Documentation
¶
Index ¶
- Constants
- func AssertGolden(t *testing.T, name string, actual string)
- func AssertGoldenStripped(t *testing.T, name string, actual string)
- func CreateTempFile(t *testing.T, content string, pattern string) string
- func CurrentUserResponse() []byte
- func DQLSuccessResponse() []byte
- func DQLSuccessResponseWithRecords(count int) []byte
- func DocumentListResponse(docType string) []byte
- func ErrorResponse(code int, message string) []byte
- func ExecuteCommand(t *testing.T, cmd *cobra.Command, args ...string) (output string, err error)
- func ExecutionResponse(executionID string, state string) []byte
- func ResetCommandFlags(cmd *cobra.Command)
- func SetupTestConfig(t *testing.T, serverURL string) (configPath string, cleanup func())
- func StripANSI(s string) string
- func UpdateGolden() bool
- func WorkflowGetResponse(id string) []byte
- func WorkflowListResponse() []byte
- type MockServer
Constants ¶
const DQLQuery = `fetch logs
| filter status == "ERROR"
| limit 100
`
DQLQuery returns a sample DQL query for testing
const DQLQueryWithTemplate = `fetch logs
| filter host == "{{.host}}"
| filter loglevel == "{{.level}}"
| limit {{.limit}}
`
DQLQueryWithTemplate returns a sample DQL query with template variables
const DashboardJSON = `` /* 168-byte string literal not displayed */
DashboardJSON returns a sample dashboard JSON for testing
const DashboardYAML = `` /* 203-byte string literal not displayed */
DashboardYAML returns a sample dashboard YAML for testing
const InvalidJSON = `{
"invalid": "json",
"missing": "closing brace"
`
InvalidJSON returns invalid JSON for testing error cases
const InvalidYAML = `
this is not: [valid: yaml
- because
it has: {incorrect: indentation
`
InvalidYAML returns invalid YAML for testing error cases
const NotebookYAML = `` /* 260-byte string literal not displayed */
NotebookYAML returns a sample notebook YAML for testing
const NotificationYAML = `` /* 148-byte string literal not displayed */
NotificationYAML returns a sample notification configuration YAML for testing
const SLODefinitionYAML = `` /* 255-byte string literal not displayed */
SLODefinitionYAML returns a sample SLO YAML for testing
const SettingsYAML = `schemaId: builtin:alerting.profile
scope: environment
value:
name: Test Alerting Profile
mzId: null
rules: []
`
SettingsYAML returns a sample settings object YAML for testing
const WorkflowJSON = `` /* 286-byte string literal not displayed */
WorkflowJSON returns a sample workflow JSON for testing
const WorkflowYAML = `` /* 256-byte string literal not displayed */
WorkflowYAML returns a sample workflow YAML for testing
Variables ¶
This section is empty.
Functions ¶
func AssertGolden ¶
AssertGolden compares actual output against a golden file identified by name. The golden file is stored at testdata/golden/<name>.golden relative to the calling test file's directory.
When run with -update, the golden file is created or overwritten with actual. When run without -update, the test fails if the file does not exist or if the content does not match.
func AssertGoldenStripped ¶
AssertGoldenStripped is like AssertGolden but strips ANSI escape sequences from the actual output before comparing. Use this for output that contains terminal color codes (e.g., charts, sparklines, braille graphs).
func CreateTempFile ¶
CreateTempFile creates a temporary file with content and returns the file path
func CurrentUserResponse ¶
func CurrentUserResponse() []byte
CurrentUserResponse creates a standard current user response
func DQLSuccessResponse ¶
func DQLSuccessResponse() []byte
DQLSuccessResponse creates a standard DQL success JSON response
func DQLSuccessResponseWithRecords ¶
DQLSuccessResponseWithRecords creates a DQL response with specified number of records
func DocumentListResponse ¶
DocumentListResponse creates a standard document list response
func ErrorResponse ¶
ErrorResponse creates a standard error JSON response
func ExecuteCommand ¶
ExecuteCommand executes a cobra command with args and returns output/error
func ExecutionResponse ¶
ExecutionResponse creates a workflow execution response
func ResetCommandFlags ¶
ResetCommandFlags resets a command's flags to allow reuse in tests.
Only the command's own flags are reset. Once cobra has merged a parent's persistent flags into cmd.Flags() (any earlier Execute or InheritedFlags call does that), resetting those too would silently clear package state a test set up before the call, such as cfgFile behind --config.
func SetupTestConfig ¶
SetupTestConfig creates a temporary config file for testing and returns the config path and cleanup function
func StripANSI ¶
StripANSI removes all ANSI escape sequences from a string. Use this for comparing output that may contain color codes.
func UpdateGolden ¶
func UpdateGolden() bool
UpdateGolden reports whether the test run was started with -update. Tests that maintain a checked-in artifact outside testdata/golden (the stability manifest at docs/STABILITY.md) use it to share one regeneration switch with the golden files.
func WorkflowGetResponse ¶
WorkflowGetResponse creates a standard workflow get JSON response
func WorkflowListResponse ¶
func WorkflowListResponse() []byte
WorkflowListResponse creates a standard workflow list JSON response
Types ¶
type MockServer ¶
MockServer represents a test HTTP server with request tracking
func NewMockServer ¶
func NewMockServer(t *testing.T, handlers map[string]http.HandlerFunc) *MockServer
NewMockServer creates a new mock server with custom handlers