testutil

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 14 Imported by: ? 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

Index

Constants

View Source
const DQLQuery = `fetch logs
| filter status == "ERROR"
| limit 100
`

DQLQuery returns a sample DQL query for testing

View Source
const DQLQueryWithTemplate = `fetch logs
| filter host == "{{.host}}"
| filter loglevel == "{{.level}}"
| limit {{.limit}}
`

DQLQueryWithTemplate returns a sample DQL query with template variables

View Source
const DashboardJSON = `` /* 168-byte string literal not displayed */

DashboardJSON returns a sample dashboard JSON for testing

View Source
const DashboardYAML = `` /* 203-byte string literal not displayed */

DashboardYAML returns a sample dashboard YAML for testing

View Source
const InvalidJSON = `{
  "invalid": "json",
  "missing": "closing brace"
`

InvalidJSON returns invalid JSON for testing error cases

View Source
const InvalidYAML = `
this is not: [valid: yaml
  - because
    it has: {incorrect: indentation
`

InvalidYAML returns invalid YAML for testing error cases

View Source
const NotebookYAML = `` /* 260-byte string literal not displayed */

NotebookYAML returns a sample notebook YAML for testing

View Source
const NotificationYAML = `` /* 148-byte string literal not displayed */

NotificationYAML returns a sample notification configuration YAML for testing

View Source
const SLODefinitionYAML = `` /* 255-byte string literal not displayed */

SLODefinitionYAML returns a sample SLO YAML for testing

View Source
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

View Source
const WorkflowJSON = `` /* 286-byte string literal not displayed */

WorkflowJSON returns a sample workflow JSON for testing

View Source
const WorkflowYAML = `` /* 256-byte string literal not displayed */

WorkflowYAML returns a sample workflow YAML for testing

Variables

This section is empty.

Functions

func AssertGolden

func AssertGolden(t *testing.T, name string, actual string)

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

func AssertGoldenStripped(t *testing.T, name string, actual string)

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

func CreateTempFile(t *testing.T, content string, pattern string) string

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

func DQLSuccessResponseWithRecords(count int) []byte

DQLSuccessResponseWithRecords creates a DQL response with specified number of records

func DocumentListResponse

func DocumentListResponse(docType string) []byte

DocumentListResponse creates a standard document list response

func ErrorResponse

func ErrorResponse(code int, message string) []byte

ErrorResponse creates a standard error JSON response

func ExecuteCommand

func ExecuteCommand(t *testing.T, cmd *cobra.Command, args ...string) (output string, err error)

ExecuteCommand executes a cobra command with args and returns output/error

func ExecutionResponse

func ExecutionResponse(executionID string, state string) []byte

ExecutionResponse creates a workflow execution response

func ResetCommandFlags

func ResetCommandFlags(cmd *cobra.Command)

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

func SetupTestConfig(t *testing.T, serverURL string) (configPath string, cleanup func())

SetupTestConfig creates a temporary config file for testing and returns the config path and cleanup function

func StripANSI

func StripANSI(s string) string

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

func WorkflowGetResponse(id string) []byte

WorkflowGetResponse creates a standard workflow get JSON response

func WorkflowListResponse

func WorkflowListResponse() []byte

WorkflowListResponse creates a standard workflow list JSON response

Types

type MockServer

type MockServer struct {
	*httptest.Server
	RequestCount int
	LastRequest  *http.Request
}

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

Jump to

Keyboard shortcuts

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