harness

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 19 Imported by: 1 module, 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 harness runs the built bitc binary in throwaway homes (spec 11).

Index

Constants

View Source
const HoldScript = `env > "$1.env"; : > "$1"; while [ ! -e "$2" ]; do sleep 0.05; done`

HoldScript is the held command: dump env to $1.env, touch $1, wait for $2.

Variables

Bin is the bitc binary under test, set by the conformance TestMain.

View Source
var RefPlugin, RefFakeAPI string

RefPlugin and RefFakeAPI are the built reference plugin and fake API (BuildReference).

View Source
var SSHFakeGate string

SSHFakeGate is the fake ssh host gate (internal/provider/ssh/sshfake/gate) the conformance TestMain built; a host file names it with `[test] ssh_gate` and `ssh_exec = "local"`.

View Source
var StubPlugin string

StubPlugin is the stub provider plugin (internal/provider/plugin/stubplugin) the conformance TestMain built; Plugin installs it for a test.

Functions

func BuildFakeDockerBinary added in v0.1.6

func BuildFakeDockerBinary(moduleRoot string) (string, error)

BuildFakeDockerBinary builds the fake docker into a temp dir and returns the binary's path. The module root is found from the test's working directory (conformance/ or an internal package).

func BuildReference

func BuildReference() (dir string, err error)

BuildReference builds the reference plugin and its fake API into a new temp dir, reproducibly (-trimpath, CGO off), and sets RefPlugin and RefFakeAPI. The caller removes dir.

func BuildSSHFake

func BuildSSHFake() (dir string, err error)

BuildSSHFake builds the fake gate into a new temp dir (the caller removes it).

func CleanupFakeDocker added in v0.1.6

func CleanupFakeDocker()

CleanupFakeDocker removes the built fake; TestMain calls it before exiting.

func ExitCode

func ExitCode(err error, ps *os.ProcessState) int

ExitCode is the shell-style code of a finished process (128+N for signal N).

func MergeEnv

func MergeEnv(base, extra []string) []string

MergeEnv overlays extra on base: "K=V" replaces K, "!K" removes it.

func ModuleRoot added in v0.1.6

func ModuleRoot(t interface{ Fatal(...any) }) string

ModuleRoot is the module root, found from the working directory (a test runs in its package).

func Q

func Q(s string) string

Q quotes s as a TOML basic string.

func ReadEnvFile

func ReadEnvFile(t *testing.T, path string) map[string]string

ReadEnvFile parses `env` output.

func WithRemoteFlag added in v0.1.1

func WithRemoteFlag(body string) string

WithRemoteFlag adds experimental_remote = true to the [host] table of a host-file body that mentions providers (a [providers.<type>] table or a pool's providers list) and lacks the key: after an existing [host] header, else as a [host] table at the end.

Types

type APICall

type APICall struct {
	Seq     int               `json:"seq"`
	Method  string            `json:"method"`
	Path    string            `json:"path"`
	Query   string            `json:"query"`
	Headers map[string]string `json:"headers"`
	Body    string            `json:"body"`
	Attach  bool              `json:"attach"`
}

APICall is one call the fake API recorded (the /__bitc/calls contract, design A.10.2).

type FakeAPI

type FakeAPI struct {
	URL string
	// contains filtered or unexported fields
}

FakeAPI is a running fake API process (a plugin author's loopback fake of their API) and the client of its /__bitc/ control contract.

func (*FakeAPI) Behave

func (f *FakeAPI) Behave(b string)

Behave is POST /__bitc/behave: the behaviour the fake shows to instances created from now on.

func (*FakeAPI) Calls

func (f *FakeAPI) Calls() []APICall

Calls is GET /__bitc/calls: every API call in order, the attach call marked.

func (*FakeAPI) Host

func (f *FakeAPI) Host() string

Host is the host part of the fake's URL.

func (*FakeAPI) Live

func (f *FakeAPI) Live() []string

Live is GET /__bitc/live: the names of the instances the fake holds.

func (*FakeAPI) Seed

func (f *FakeAPI) Seed(name, owner string, created, expires time.Time) string

Seed lists an instance with no process (optional part of the contract); it returns its id.

func (*FakeAPI) SetSpend

func (f *FakeAPI) SetSpend(usd float64)

SetSpend sets the spend the fake's billing endpoint reports (optional part of the contract).

func (*FakeAPI) Torn

func (f *FakeAPI) Torn() []string

Torn is GET /__bitc/torn: the ids of the instances deleted so far.

type FakeDocker added in v0.1.6

type FakeDocker struct {
	State string // $FAKE_DOCKER_DIR
	// contains filtered or unexported fields
}

FakeDocker is one test's fake docker: a `docker` on PATH for every bitc the test starts, and the state directory it records into.

func (*FakeDocker) Calls added in v0.1.6

func (f *FakeDocker) Calls() [][]string

Calls is every docker call so far, argv without the program name, oldest first.

func (*FakeDocker) CallsOf added in v0.1.6

func (f *FakeDocker) CallsOf(verb string) [][]string

CallsOf is the calls whose first argument is verb ("run", "rm", "ps").

func (*FakeDocker) Container added in v0.1.6

func (f *FakeDocker) Container(name string) (fakeRec, bool)

Container returns the fake container name and whether it exists.

func (*FakeDocker) Created added in v0.1.6

func (f *FakeDocker) Created(name string) bool

Created reports whether the fake ever created a container of that name (a run killed before the CLI got that far creates none).

func (*FakeDocker) DockerHosts added in v0.1.6

func (f *FakeDocker) DockerHosts() []string

DockerHosts is the DOCKER_HOST each docker call ran with, oldest first ("" when unset).

func (*FakeDocker) EnvFile added in v0.1.6

func (f *FakeDocker) EnvFile(name string) (path, mode, body string, ok bool)

EnvFile is what the fake found in the --env-file of the run that named its container name: the file's path, its mode ("0600") and its body, taken when docker run started.

func (*FakeDocker) Exists added in v0.1.6

func (f *FakeDocker) Exists(name string) bool

Exists reports whether the container exists (created, running or exited without --rm).

func (*FakeDocker) HoldRecord added in v0.1.6

func (f *FakeDocker) HoldRecord()

HoldRecord makes this fake write a container's "running" record (its Pgid) only after ReleaseRecord(name): the command then always runs before the record says it started. Off by default; call it before starting bitc.

func (*FakeDocker) Plant added in v0.1.6

func (f *FakeDocker) Plant(name string, labels map[string]string) string

Plant adds a container that nothing runs, as a leftover of a bitc that died: an orphan to sweep. It returns the container's id.

func (*FakeDocker) ReleaseAllRecords added in v0.1.6

func (f *FakeDocker) ReleaseAllRecords()

ReleaseAllRecords releases every container's record, those not yet started too.

func (*FakeDocker) ReleaseRecord added in v0.1.6

func (f *FakeDocker) ReleaseRecord(name string)

ReleaseRecord lets the fake write the running record of the container name (see HoldRecord).

func (*FakeDocker) RemoveRecordGates added in v0.1.6

func (f *FakeDocker) RemoveRecordGates()

RemoveRecordGates deletes the gate directory of HoldRecord, as the end of a test does: a held fake then stops waiting and writes its record. ReleaseRecord must not be called after it.

func (*FakeDocker) Removed added in v0.1.6

func (f *FakeDocker) Removed(name string) bool

Removed reports whether a `docker rm` removed the container of that name (by whatever it was given).

func (*FakeDocker) RemovedBy added in v0.1.6

func (f *FakeDocker) RemovedBy() []string

RemovedBy is what each `docker rm` that removed a container was given (an id, or a name).

func (*FakeDocker) Running added in v0.1.6

func (f *FakeDocker) Running(name string) bool

Running reports whether the container's command has started (its process group is recorded).

type H

type H struct {
	T      *testing.T
	Root   string
	State  string
	Config string
	Cwd    string
	Env    []string
	// contains filtered or unexported fields
}

H is one test's sandbox: HOME, state dir and host config under a temp dir.

func New

func New(t *testing.T) *H

New makes a sandbox with a host file holding only "version = 1" and the [test] table.

func (*H) Atoi

func (h *H) Atoi(s string) int

Atoi is strconv.Atoi that fails the test.

func (*H) FakeDocker added in v0.1.6

func (h *H) FakeDocker() *FakeDocker

FakeDocker puts the fake docker first on PATH for bitc and its children in this sandbox.

func (*H) Hold

func (h *H) Hold(env []string, runArgs ...string) *Holder

Hold runs `bitc run <runArgs...> -- sh -c HoldScript` and waits until the command runs. runArgs are run flags followed by the pool.

func (*H) HostConfig

func (h *H) HostConfig(body string)

HostConfig writes the host file: "version = 1", body, then [test] with accounting_dir under Root and every seam added with Seam; a body naming sprites gets [test] allow_sprites (the sprites refusal's test-only bypass, honoured only for loopback endpoints). A body that configures a remote provider gets [host] experimental_remote = true (WithRemoteFlag); EX1 writes its host files whole instead.

func (*H) Origin

func (h *H) Origin(name string) string

Origin is the path of the bare origin that Repo(name) made.

func (*H) Plugin

func (h *H) Plugin(typ string) (path, sum string)

Plugin copies the stub plugin to Root/plugins/bitc-provider-<typ> (a private directory, 0700, so the pin checks of providers delta A.2 pass) and returns its path and sha256.

func (*H) PluginFrom

func (h *H) PluginFrom(typ, src string) (path, sum string)

PluginFrom installs the plugin binary src as Root/plugins/bitc-provider-<typ> (0755, in a 0700 directory) and returns its path and sha256: the path + sha256 pin a real host writes.

func (*H) Repo

func (h *H) Repo(name string, files map[string]string) string

Repo makes a git work tree Root/<name> with files committed, and returns its path.

func (*H) Run

func (h *H) Run(args ...string) Result

Run runs bitc with args and waits.

func (*H) RunWith

func (h *H) RunWith(env []string, args ...string) Result

RunWith runs bitc with extra env entries ("K=V" sets, "!K" removes) and waits.

func (*H) Seam

func (h *H) Seam(line string)

Seam adds one `key = value` line to the [test] table and rewrites the host file.

func (*H) SetSeam

func (h *H) SetSeam(key, value string)

SetSeam sets one [test] key, replacing an earlier line for it, and rewrites the host file.

func (*H) Start

func (h *H) Start(args ...string) *Proc

Start starts bitc in its own process group.

func (*H) StartFakeAPI

func (h *H) StartFakeAPI(bin string) *FakeAPI

StartFakeAPI starts the fake API binary on a loopback port, with this bitc as every instance's agent, and stops it with the test. The binary prints "listening <url>" once it serves.

func (*H) StartWith

func (h *H) StartWith(env []string, args ...string) *Proc

StartWith starts bitc with extra env entries in its own process group.

func (*H) Track

func (h *H) Track(pid int)

Track registers a pid whose process group the cleanup kills (detached jobs).

func (*H) Until

func (h *H) Until(cond func() bool, d time.Duration)

Until polls cond every 20 ms until it holds or d passes.

func (*H) Write

func (h *H) Write(path, body string, mode os.FileMode)

Write writes a file, creating parent dirs (0700).

type Holder

type Holder struct {
	Env  map[string]string
	Proc *Proc
	// contains filtered or unexported fields
}

Holder is a bitc run holding a slot until Release.

func (*Holder) Release

func (hd *Holder) Release() Result

Release lets the held command finish and returns bitc's result.

type Proc

type Proc struct {
	Cmd *exec.Cmd
	// contains filtered or unexported fields
}

Proc is a running bitc.

func (*Proc) Exited

func (p *Proc) Exited() bool

Exited reports whether the process has ended.

func (*Proc) Signal

func (p *Proc) Signal(sig syscall.Signal)

Signal sends sig to the process (not its group).

func (*Proc) Stdout

func (p *Proc) Stdout() string

Stdout is what the process has printed so far.

func (*Proc) Wait

func (p *Proc) Wait() Result

Wait waits up to 60 s, then kills bitc's group and waits at most 10 s more; it never hangs.

type Result

type Result struct {
	Code   int
	Stdout string
	Stderr string
}

Result is one finished bitc process.

Jump to

Keyboard shortcuts

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