Documentation
¶
Overview ¶
Package runner abstracts execution of Apple's `container` CLI so that the orchestration engine can be unit-tested without the binary present. The real implementation shells out; tests substitute a fake.
Index ¶
- type Call
- type Exec
- type Fake
- func (f *Fake) CommandArgs() []string
- func (f *Fake) CountMatching(substr string) int
- func (f *Fake) On(match string, result Result, err error) *Fake
- func (f *Fake) OnSequence(match string, results ...Result) *Fake
- func (f *Fake) Run(_ context.Context, args ...string) (Result, error)
- func (f *Fake) RunInteractive(_ context.Context, args ...string) error
- func (f *Fake) RunWithOutput(_ context.Context, stdout, stderr io.Writer, args ...string) error
- type Result
- type Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Exec ¶
type Exec struct {
// Binary is the executable to invoke; defaults to "container".
Binary string
// Stdout/Stderr are used by RunInteractive; default to the process streams.
Stdout *os.File
Stderr *os.File
Stdin *os.File
}
Exec is the production Runner that invokes the container binary.
func NewExec ¶
NewExec returns an Exec runner using the given binary name (or "container" when empty) wired to the process standard streams.
func (*Exec) RunInteractive ¶
RunInteractive implements Runner. Standard output and error are wired to the process streams. Standard input is attached only when it is a terminal: the container runtime rejects some non-terminal stdin devices (ENODEV), and a non-interactive invocation (script/pipe/CI) doesn't need it.
type Fake ¶
type Fake struct {
Calls []Call
// contains filtered or unexported fields
}
Fake is an in-memory Runner for tests. It records every invocation and lets the test program canned responses or errors keyed by an argument substring.
func (*Fake) CommandArgs ¶
CommandArgs returns the recorded calls as joined argument strings, for terse assertions in tests.
func (*Fake) CountMatching ¶
CountMatching returns how many recorded calls contain the given substring.
func (*Fake) OnSequence ¶
OnSequence registers an ordered sequence of responses for matching calls. Successive matches return successive results; the last result repeats thereafter. Useful for simulating "unhealthy then healthy" transitions.
func (*Fake) RunInteractive ¶
RunInteractive implements Runner, recording the call.
type Runner ¶
type Runner interface {
// Run executes `container <args...>`, capturing stdout/stderr. A non-zero
// exit code is returned in Result and also surfaced as an error.
Run(ctx context.Context, args ...string) (Result, error)
// RunInteractive executes `container <args...>` wired directly to the
// process stdio (for attached/interactive containers and log following).
RunInteractive(ctx context.Context, args ...string) error
// RunWithOutput executes `container <args...>`, streaming stdout and stderr
// to the given writers (no stdin). It is used for concurrent log
// multiplexing, where each container's output is prefixed.
RunWithOutput(ctx context.Context, stdout, stderr io.Writer, args ...string) error
}
Runner executes container CLI commands.