Documentation
¶
Overview ¶
Package exectest provides a fake exec.Runner for unit-testing capability packages with no host, no sudo, and no container. It is the keystone of the additive unit tier in the SDK rework (sdk/docs/sdk-rework-design.md §6): because every capability handle is built with an explicit Runner, a test passes a FakeRunner and asserts on the exact Commands the capability built.
Index ¶
- type FakeRunner
- func (f *FakeRunner) Backend() exec.PrivilegeBackend
- func (f *FakeRunner) CallContexts() []context.Context
- func (f *FakeRunner) Calls() []exec.Command
- func (f *FakeRunner) Push(r exec.Result, err error)
- func (f *FakeRunner) Run(ctx context.Context, c exec.Command) (exec.Result, error)
- func (f *FakeRunner) Stream(ctx context.Context, c exec.Command, onLine exec.OutputCallback) (exec.Result, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FakeRunner ¶
type FakeRunner struct {
// contains filtered or unexported fields
}
FakeRunner is an exec.Runner that records every Command it receives and returns scripted Results in FIFO order. An unscripted call returns a clean success (zero Result, nil error). Safe for concurrent use.
func New ¶
func New(backend exec.PrivilegeBackend) *FakeRunner
New returns a FakeRunner that reports the given privilege backend. The zero value defaults to exec.Direct (the common unit-test runner).
func (*FakeRunner) Backend ¶
func (f *FakeRunner) Backend() exec.PrivilegeBackend
Backend reports the configured privilege backend, so a capability under test can branch on Runner.Backend() (e.g. fs's fd-safe vs sudo path).
func (*FakeRunner) CallContexts ¶
func (f *FakeRunner) CallContexts() []context.Context
CallContexts returns the context received with each recorded Command, in order (1:1 with Calls). Lets a test assert the invariant that every escalated call ran under a deadline-bounded context — see sys/user TestExecBoundsContext.
func (*FakeRunner) Calls ¶
func (f *FakeRunner) Calls() []exec.Command
Calls returns every Command received, in order.
func (*FakeRunner) Push ¶
func (f *FakeRunner) Push(r exec.Result, err error)
Push scripts the next Run/Stream outcome (FIFO).
func (*FakeRunner) Run ¶
Run records the Command and returns the next scripted Result. An already-cancelled context short-circuits with ctx.Err() WITHOUT consuming a scripted result — mirroring the real Runner, so a capability's ctx handling can be unit-tested faithfully.
func (*FakeRunner) Stream ¶
func (f *FakeRunner) Stream(ctx context.Context, c exec.Command, onLine exec.OutputCallback) (exec.Result, error)
Stream records the Command, returns the next scripted Result, and replays the scripted stdout/stderr to onLine line-by-line so streaming capabilities can be exercised without a real process. A cancelled context short-circuits as in Run (no scripted result consumed, no replay).