Documentation
¶
Overview ¶
Package exec provides command execution with mocking support for testing.
Index ¶
- type CommandExecutor
- type CommandResult
- type ExecutedCommand
- type MockExecutor
- func (m *MockExecutor) AddCommand(name string, args []string, stdout, stderr string, err error)
- func (m *MockExecutor) AddGHAPIJobs(owner, repo string, runID int64, jobs string)
- func (m *MockExecutor) AddGHAPILatestRun(owner, repo, workflow string, runID int64, status string)
- func (m *MockExecutor) AddGHAPIRun(owner, repo string, runID int64, status, conclusion string)
- func (m *MockExecutor) AddGHAuthStatus(authenticated bool, username string)
- func (m *MockExecutor) AddGHRunView(runID, jobID int64, logOutput string)
- func (m *MockExecutor) AddGHRunViewError(runID, jobID int64, stderr string, err error)
- func (m *MockExecutor) AddGHVersion(version string)
- func (m *MockExecutor) AddGHWorkflowRun(workflow, branch string, inputs map[string]string)
- func (m *MockExecutor) AddGHWorkflowRunError(workflow, branch, stderr string, err error)
- func (m *MockExecutor) Execute(name string, args ...string) (string, string, error)
- func (m *MockExecutor) Reset()
- type RealExecutor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandExecutor ¶
type CommandExecutor interface {
// Execute runs a command with the given name and arguments.
// Returns stdout, stderr, and any error.
Execute(name string, args ...string) (stdout, stderr string, err error)
}
CommandExecutor defines an interface for executing external commands. This allows us to mock command execution in tests.
type CommandResult ¶
CommandResult represents the result of a command execution.
type ExecutedCommand ¶
ExecutedCommand tracks a command that was executed.
type MockExecutor ¶
type MockExecutor struct {
// Commands maps command patterns to responses.
// Key format: "command arg1 arg2"
Commands map[string]*CommandResult
// DefaultResult is returned when no specific command matches.
DefaultResult *CommandResult
// ExecutedCommands tracks all commands that were executed.
ExecutedCommands []ExecutedCommand
}
MockExecutor simulates command execution for testing.
func NewMockExecutor ¶
func NewMockExecutor() *MockExecutor
NewMockExecutor creates a new mock executor.
func (*MockExecutor) AddCommand ¶
func (m *MockExecutor) AddCommand(name string, args []string, stdout, stderr string, err error)
AddCommand registers a command response.
func (*MockExecutor) AddGHAPIJobs ¶
func (m *MockExecutor) AddGHAPIJobs(owner, repo string, runID int64, jobs string)
AddGHAPIJobs mocks a gh api call for workflow run jobs.
func (*MockExecutor) AddGHAPILatestRun ¶
func (m *MockExecutor) AddGHAPILatestRun(owner, repo, workflow string, runID int64, status string)
AddGHAPILatestRun mocks a gh api call for the latest workflow run.
func (*MockExecutor) AddGHAPIRun ¶
func (m *MockExecutor) AddGHAPIRun(owner, repo string, runID int64, status, conclusion string)
AddGHAPIRun mocks a gh api call for workflow run data.
func (*MockExecutor) AddGHAuthStatus ¶
func (m *MockExecutor) AddGHAuthStatus(authenticated bool, username string)
AddGHAuthStatus mocks the gh auth status command.
func (*MockExecutor) AddGHRunView ¶
func (m *MockExecutor) AddGHRunView(runID, jobID int64, logOutput string)
AddGHRunView is a convenience method for adding gh run view commands.
func (*MockExecutor) AddGHRunViewError ¶
func (m *MockExecutor) AddGHRunViewError(runID, jobID int64, stderr string, err error)
AddGHRunViewError is a convenience method for adding failing gh run view commands.
func (*MockExecutor) AddGHVersion ¶
func (m *MockExecutor) AddGHVersion(version string)
AddGHVersion mocks the gh --version command.
func (*MockExecutor) AddGHWorkflowRun ¶
func (m *MockExecutor) AddGHWorkflowRun(workflow, branch string, inputs map[string]string)
AddGHWorkflowRun mocks a successful gh workflow run command.
func (*MockExecutor) AddGHWorkflowRunError ¶
func (m *MockExecutor) AddGHWorkflowRunError(workflow, branch, stderr string, err error)
AddGHWorkflowRunError mocks a failing gh workflow run command.
func (*MockExecutor) Execute ¶
Execute simulates command execution by looking up the command in the Commands map.
func (*MockExecutor) Reset ¶
func (m *MockExecutor) Reset()
Reset clears all command history and configurations.
type RealExecutor ¶
type RealExecutor struct{}
RealExecutor executes actual system commands.
func NewRealExecutor ¶
func NewRealExecutor() *RealExecutor
NewRealExecutor creates an executor that runs real commands.