runner

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	Args        []string
	Interactive bool
}

Call records a single invocation made against a Fake runner.

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

func NewExec(binary string) *Exec

NewExec returns an Exec runner using the given binary name (or "container" when empty) wired to the process standard streams.

func (*Exec) Run

func (e *Exec) Run(ctx context.Context, args ...string) (Result, error)

Run implements Runner.

func (*Exec) RunInteractive

func (e *Exec) RunInteractive(ctx context.Context, args ...string) error

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.

func (*Exec) RunWithOutput

func (e *Exec) RunWithOutput(ctx context.Context, stdout, stderr io.Writer, args ...string) error

RunWithOutput implements Runner.

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

func (f *Fake) CommandArgs() []string

CommandArgs returns the recorded calls as joined argument strings, for terse assertions in tests.

func (*Fake) CountMatching

func (f *Fake) CountMatching(substr string) int

CountMatching returns how many recorded calls contain the given substring.

func (*Fake) On

func (f *Fake) On(match string, result Result, err error) *Fake

On registers a canned response for any call whose joined args contain match.

func (*Fake) OnSequence

func (f *Fake) OnSequence(match string, results ...Result) *Fake

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) Run

func (f *Fake) Run(_ context.Context, args ...string) (Result, error)

Run implements Runner, recording the call and returning any canned response.

func (*Fake) RunInteractive

func (f *Fake) RunInteractive(_ context.Context, args ...string) error

RunInteractive implements Runner, recording the call.

func (*Fake) RunWithOutput

func (f *Fake) RunWithOutput(_ context.Context, stdout, stderr io.Writer, args ...string) error

RunWithOutput implements Runner, recording the call and writing any canned stdout to the provided writer (so log-multiplexing can be tested).

type Result

type Result struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

Result captures the outcome of a single container CLI invocation.

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.

Jump to

Keyboard shortcuts

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