Documentation
¶
Overview ¶
Package testutil provides testing utilities, fixtures, and mocks for unit tests.
Index ¶
- func AssertCommand(t *testing.T, cmd exec.ExecutedCommand, expectedArgs ...string)
- func AssertContains(t *testing.T, haystack, needle string, msgAndArgs ...any)
- func AssertEqual[T comparable](t *testing.T, got, want T, msgAndArgs ...any)
- func AssertFalse(t *testing.T, condition bool, msgAndArgs ...any)
- func AssertNil(t *testing.T, value any, msgAndArgs ...any)
- func AssertNotEqual[T comparable](t *testing.T, got, want T, msgAndArgs ...any)
- func AssertNotNil(t *testing.T, value any, msgAndArgs ...any)
- func AssertStepLogNames(t *testing.T, stepLogs []*logs.StepLogs, expectedNames []string)
- func AssertTrue(t *testing.T, condition bool, msgAndArgs ...any)
- func DrainChainUpdates(t *testing.T, updates <-chan chain.ChainUpdate, timeout time.Duration)
- func GenerateANSILog() string
- func GenerateLargeLogFixture(lines int) string
- func GenerateLargeLogWithErrors(lines int, errorRate float64) string
- func GenerateLogWithPatterns(lines int, patterns []string) string
- func GenerateLogWithTimestamps(lines int) string
- func GenerateMixedLog(lines int) string
- func GenerateMultiStepLog(numSteps, linesPerStep int) string
- func GenerateUnicodeLog() string
- func LoadFixture(tb testing.TB, filename string) string
- func MustMarshalJSON(t *testing.T, v any) string
- func NewTestHistory(repo string, records []struct{ ... }) *frecency.Store
- func SimpleWorkflow(name, filename string) workflow.File
- func WorkflowFixture(name, filename string, inputs map[string]workflow.Input) workflow.File
- func WorkflowWithBoolean(name, filename, inputName string, defaultVal bool) workflow.File
- func WorkflowWithChoice(name, filename, inputName string, options []string, defaultVal string) workflow.File
- func WorkflowWithString(name, filename, inputName, defaultVal, description string) workflow.File
- type MockGitHubClient
- func (m *MockGitHubClient) GetLatestRun(workflow string) (*github.WorkflowRun, error)
- func (m *MockGitHubClient) GetWorkflowRun(runID int64) (*github.WorkflowRun, error)
- func (m *MockGitHubClient) GetWorkflowRunJobs(runID int64) ([]github.Job, error)
- func (m *MockGitHubClient) Owner() string
- func (m *MockGitHubClient) Repo() string
- func (m *MockGitHubClient) WithError(err error) *MockGitHubClient
- func (m *MockGitHubClient) WithJobs(runID int64, jobs []github.Job) *MockGitHubClient
- func (m *MockGitHubClient) WithOwnerRepo(owner, repo string) *MockGitHubClient
- func (m *MockGitHubClient) WithRun(run *github.WorkflowRun) *MockGitHubClient
- type MockRunWatcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertCommand ¶
func AssertCommand(t *testing.T, cmd exec.ExecutedCommand, expectedArgs ...string)
AssertCommand verifies that an executed command matches expected arguments.
func AssertContains ¶
AssertContains fails the test if haystack doesn't contain needle.
func AssertEqual ¶
func AssertEqual[T comparable](t *testing.T, got, want T, msgAndArgs ...any)
AssertEqual fails the test if got != want.
func AssertFalse ¶
AssertFalse fails the test if condition is true.
func AssertNotEqual ¶
func AssertNotEqual[T comparable](t *testing.T, got, want T, msgAndArgs ...any)
AssertNotEqual fails the test if got == want.
func AssertNotNil ¶
AssertNotNil fails the test if value is nil.
func AssertStepLogNames ¶
AssertStepLogNames verifies that step logs have the expected names.
func AssertTrue ¶
AssertTrue fails the test if condition is false.
func DrainChainUpdates ¶
DrainChainUpdates reads all updates from the channel until it closes or times out.
func GenerateANSILog ¶
func GenerateANSILog() string
GenerateANSILog creates logs with ANSI color codes. Tests proper handling of terminal color escape sequences. Includes ##[group] markers for proper parsing.
func GenerateLargeLogFixture ¶
GenerateLargeLogFixture creates a realistic log file with N lines. Uses GitHub Actions log format patterns for authenticity.
func GenerateLargeLogWithErrors ¶
GenerateLargeLogWithErrors creates a log with error patterns. The errorRate is a float between 0 and 1 indicating percentage of lines that should be errors.
func GenerateLogWithPatterns ¶
GenerateLogWithPatterns creates a log with specific searchable patterns. Useful for testing search and filter functionality.
func GenerateLogWithTimestamps ¶
GenerateLogWithTimestamps creates log lines with timestamp prefixes. Tests timestamp parsing and display.
func GenerateMixedLog ¶
GenerateMixedLog creates a log with various patterns for comprehensive testing. Includes errors, warnings, unicode, ANSI codes, and normal logs.
func GenerateMultiStepLog ¶
GenerateMultiStepLog creates a log output with multiple GitHub Actions steps. Simulates a real workflow run with step grouping.
func GenerateUnicodeLog ¶
func GenerateUnicodeLog() string
GenerateUnicodeLog creates logs with unicode characters. Tests proper handling of international characters and emoji.
func LoadFixture ¶
LoadFixture loads a test fixture file from testdata. Helper function for tests and benchmarks.
func MustMarshalJSON ¶
MustMarshalJSON marshals v to JSON, failing the test if an error occurs.
func NewTestHistory ¶
func NewTestHistory(repo string, records []struct { Inputs map[string]string Workflow string Branch string }, ) *frecency.Store
NewTestHistory creates a history store with test data.
func SimpleWorkflow ¶
SimpleWorkflow creates a basic workflow with no inputs.
func WorkflowFixture ¶
WorkflowFixture creates a test workflow with specified properties.
func WorkflowWithBoolean ¶
WorkflowWithBoolean creates a workflow with a boolean input.
func WorkflowWithChoice ¶
func WorkflowWithChoice(name, filename, inputName string, options []string, defaultVal string) workflow.File
WorkflowWithChoice creates a workflow with a choice input.
func WorkflowWithString ¶
WorkflowWithString creates a workflow with a string input.
Types ¶
type MockGitHubClient ¶
type MockGitHubClient struct {
Err error
Runs map[int64]*github.WorkflowRun
Jobs map[int64][]github.Job
LatestByWorkflow map[string]int64
LatestID int64
// contains filtered or unexported fields
}
MockGitHubClient implements both chain.GitHubClient and watcher.GitHubClient interfaces.
func NewMockGitHubClient ¶
func NewMockGitHubClient() *MockGitHubClient
NewMockGitHubClient creates a MockGitHubClient with sensible defaults.
func (*MockGitHubClient) GetLatestRun ¶
func (m *MockGitHubClient) GetLatestRun(workflow string) (*github.WorkflowRun, error)
GetLatestRun returns the mocked latest run for workflow.
func (*MockGitHubClient) GetWorkflowRun ¶
func (m *MockGitHubClient) GetWorkflowRun(runID int64) (*github.WorkflowRun, error)
GetWorkflowRun returns the mocked run for runID, or a queued stub if none is configured.
func (*MockGitHubClient) GetWorkflowRunJobs ¶
func (m *MockGitHubClient) GetWorkflowRunJobs(runID int64) ([]github.Job, error)
GetWorkflowRunJobs returns the mocked jobs for runID.
func (*MockGitHubClient) Owner ¶
func (m *MockGitHubClient) Owner() string
Owner returns the mocked repository owner.
func (*MockGitHubClient) Repo ¶
func (m *MockGitHubClient) Repo() string
Repo returns the mocked repository name.
func (*MockGitHubClient) WithError ¶
func (m *MockGitHubClient) WithError(err error) *MockGitHubClient
WithError sets the error to return from all methods.
func (*MockGitHubClient) WithJobs ¶
func (m *MockGitHubClient) WithJobs(runID int64, jobs []github.Job) *MockGitHubClient
WithJobs adds jobs for a run to the mock.
func (*MockGitHubClient) WithOwnerRepo ¶
func (m *MockGitHubClient) WithOwnerRepo(owner, repo string) *MockGitHubClient
WithOwnerRepo sets the owner and repo for the mock client.
func (*MockGitHubClient) WithRun ¶
func (m *MockGitHubClient) WithRun(run *github.WorkflowRun) *MockGitHubClient
WithRun adds a workflow run to the mock.
type MockRunWatcher ¶
MockRunWatcher implements chain.RunWatcher interface.
func NewMockRunWatcher ¶
func NewMockRunWatcher() *MockRunWatcher
NewMockRunWatcher creates a new MockRunWatcher.
func (*MockRunWatcher) SendUpdate ¶
func (m *MockRunWatcher) SendUpdate(update watcher.RunUpdate)
SendUpdate sends an update to the mock watcher's channel (for testing).
func (*MockRunWatcher) Unwatch ¶
func (m *MockRunWatcher) Unwatch(runID int64)
Unwatch removes runID from the watched set.
func (*MockRunWatcher) Updates ¶
func (m *MockRunWatcher) Updates() <-chan watcher.RunUpdate
Updates returns the mocked run update channel.
func (*MockRunWatcher) Watch ¶
func (m *MockRunWatcher) Watch(runID int64, workflowName string)
Watch records runID as watched for workflowName.