Documentation
¶
Overview ¶
Package mock provides test doubles for the cmdexec.Executor interface.
Index ¶
- type Call
- type Executor
- type RecordedCall
- type Recorder
- type RecordingExecutor
- func (r *RecordingExecutor) Calls() []RecordedCall
- func (r *RecordingExecutor) Dump() string
- func (r *RecordingExecutor) Run(ctx context.Context, name string, args ...string) (string, string, error)
- func (r *RecordingExecutor) RunWithStdin(ctx context.Context, stdin io.Reader, name string, args ...string) (string, string, error)
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Call ¶
type Call struct {
Name string
Args []string
Stdin string // captured stdin content (empty if no stdin)
}
Call records a single invocation of Executor.
type Executor ¶
type Executor struct {
// OnCall, if set, is called to produce a result for each invocation.
// The args slice contains the subcommand and its arguments
// (e.g. ["inspect", "sind-dns"]). Stdin is non-empty for RunWithStdin calls.
OnCall func(args []string, stdin string) Result
Calls []Call
// contains filtered or unexported fields
}
Executor records all calls and returns preconfigured results. It is safe for concurrent use.
Results are dispatched in two modes:
- If OnCall is set, it is called for every invocation to produce a result.
- Otherwise, results queued via AddResult are returned in FIFO order.
OnCall is useful when multiple goroutines share a Executor and result dispatch must be based on command arguments rather than call order.
func (*Executor) AddResult ¶
AddResult enqueues a result to be returned by the next Run or RunWithStdin call. Only used when OnCall is nil.
type RecordedCall ¶
RecordedCall captures one invocation of the executor.
type Recorder ¶
type Recorder struct {
*RecordingExecutor
// contains filtered or unexported fields
}
Recorder holds a RecordingExecutor and the underlying mock (if any). In unit mode, mock is non-nil and AddResult configures responses. In integration mode, mock is nil and AddResult is a no-op.
func NewIntegrationRecorder ¶
func NewIntegrationRecorder() *Recorder
NewIntegrationRecorder returns a Recorder backed by an OSExecutor.
func NewRecorder ¶
func NewRecorder() *Recorder
NewRecorder returns a Recorder backed by a Executor.
func (*Recorder) IsIntegration ¶
IsIntegration returns true when running against real executors.
type RecordingExecutor ¶
RecordingExecutor wraps another Executor and records all calls with their results. Useful for observing actual CLI I/O during tests.
func (*RecordingExecutor) Calls ¶
func (r *RecordingExecutor) Calls() []RecordedCall
Calls returns a copy of all recorded calls.
func (*RecordingExecutor) Dump ¶
func (r *RecordingExecutor) Dump() string
Dump returns a human-readable log of all recorded calls.