Documentation
¶
Overview ¶
Package mockexec provides a configurable mock for shell command execution in functional tests. It is designed to run as a test service alongside the mock HTTP server — configure it via `spec.testing.config.services` with `type: exec`.
Mock rules match commands by exact string or regex and return predefined stdout, stderr, and exit codes. Unmatched commands can fall through to real execution or fail with an error (configurable via Passthrough).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallRecord ¶
CallRecord records a command that was intercepted.
type MockExec ¶
type MockExec struct {
// contains filtered or unexported fields
}
MockExec intercepts shell commands and returns predefined responses.
func New ¶
New creates a new MockExec with the given rules. Rules are matched in order — the first matching rule wins.
func (*MockExec) Calls ¶
func (m *MockExec) Calls() []CallRecord
Calls returns a copy of all recorded call records.
type Option ¶
type Option func(*MockExec)
Option configures a MockExec.
func WithPassthrough ¶
WithPassthrough allows unmatched commands to execute normally via the real shellexec.Run. When false (default), unmatched commands return an error.
type Rule ¶
type Rule struct {
// Command is an exact command string to match. Mutually exclusive with Pattern.
Command string `json:"command,omitempty" yaml:"command,omitempty" doc:"Exact command string to match" maxLength:"1000"`
// Pattern is a regex pattern to match against the command. Mutually exclusive with Command.
Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty" doc:"Regex pattern to match against command" maxLength:"500"`
// Stdout is the mock standard output to return.
Stdout string `json:"stdout,omitempty" yaml:"stdout,omitempty" doc:"Mock stdout response" maxLength:"100000"`
// Stderr is the mock standard error to return.
Stderr string `json:"stderr,omitempty" yaml:"stderr,omitempty" doc:"Mock stderr response" maxLength:"100000"`
// ExitCode is the mock exit code (default: 0).
ExitCode int `json:"exitCode,omitempty" yaml:"exitCode,omitempty" doc:"Mock exit code" maximum:"255"`
// contains filtered or unexported fields
}
Rule defines a single mock command response.