Documentation
¶
Overview ¶
Package isolationtest is the conformance suite every isolation backend must pass. A backend package runs it from a test file:
func TestConformance(t *testing.T) {
isolationtest.Run(t, func(t *testing.T) (isolation.Backend, isolationtest.Options) {
// Build the backend over stubbed commands and return how to drive it.
})
}
The suite calls newBackend once per subtest, so each case starts from a fresh backend and fresh host state. It does not run subtests in parallel, which lets runners use t.Setenv to stub commands on PATH.
The suite covers prepare, start, stop, restart, exec, logs, destroy, idempotence of each, and recovery after an injected failure. It asserts only the contract in pkg/agent/isolation; backend specifics belong in the backend's own tests.
A field of Options left at its zero value skips only the cases that need it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInjected = errors.New("injected failure")
ErrInjected is the error runners should return for an injected failure, so the suite can tell it from a real one.
Functions ¶
func Golden ¶
Golden compares got with testdata/<name> in the calling package's directory. Running the package's tests with -update rewrites the file first.
func Run ¶
func Run(t *testing.T, newBackend NewBackend)
Run executes the conformance suite against the backend newBackend builds.
Types ¶
type NewBackend ¶
NewBackend builds a fresh backend and the Options to drive it.
type Options ¶
type Options struct {
// Spec is passed to Prepare. Slot is required.
Spec isolation.NodeSpec
// ExecArgs is a command that succeeds in a running node stack, and ExecWant
// is the stdout it produces (trailing newlines trimmed). Required for the
// exec cases.
ExecArgs []string
ExecWant string
// ExecFailArgs, when set, is a command that exits non-zero. Exec of it must
// return an error.
ExecFailArgs []string
// Fail arranges for the next call of op to fail once with err and then
// succeed again. When nil the failure recovery cases are skipped.
Fail func(op Op, err error)
// Grants, when set, are requests the backend must honor: Prepare with them
// in Spec.Grants succeeds and the node starts, runs and stops. They must be
// satisfiable on the runner's host, for example by creating the paths they
// name in a temporary tree.
Grants []isolation.Grant
// RefusedGrants, when set, are requests the backend cannot honor. Prepare
// with any one of them must return an error rather than ignore the grant,
// and must leave the slot preparable. Backends that honor everything leave
// it empty.
RefusedGrants []isolation.Grant
// SkipLogs skips the Logs case for backends that cannot stream logs under
// test.
SkipLogs bool
// LogsWant, when set, must appear in the output of Logs for a started node.
// A runner whose log command echoes its arguments uses it to check the
// backend asked for the right journal.
LogsWant string
// ExecStoppedFails says Exec on a stopped node must return an error, as for
// a machine that is not up. Backends whose node stack is the host leave it
// false, and either outcome is accepted.
ExecStoppedFails bool
}
Options tells the suite how to drive and observe the backend under test.