exectest

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 added in v0.5.3

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

func (f *FakeRunner) Run(ctx context.Context, c exec.Command) (exec.Result, error)

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

Jump to

Keyboard shortcuts

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