exec

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package exec provides command execution with mocking support for testing.

Index

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

type CommandResult struct {
	Stdout string
	Stderr string
	Error  error
}

CommandResult represents the result of a command execution.

type ExecutedCommand

type ExecutedCommand struct {
	Name string
	Args []string
}

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

func (m *MockExecutor) Execute(name string, args ...string) (string, string, error)

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.

func (*RealExecutor) Execute

func (e *RealExecutor) Execute(name string, args ...string) (string, string, error)

Execute runs the actual command using os/exec. It includes a safety check to prevent accidental mutation of GitHub resources during tests.

Jump to

Keyboard shortcuts

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