Documentation
¶
Overview ¶
Package harness runs the built bitc binary in throwaway homes (spec 11).
Index ¶
- Constants
- Variables
- func BuildFakeDockerBinary(moduleRoot string) (string, error)
- func BuildReference() (dir string, err error)
- func BuildSSHFake() (dir string, err error)
- func CleanupFakeDocker()
- func ExitCode(err error, ps *os.ProcessState) int
- func MergeEnv(base, extra []string) []string
- func ModuleRoot(t interface{ ... }) string
- func Q(s string) string
- func ReadEnvFile(t *testing.T, path string) map[string]string
- func WithRemoteFlag(body string) string
- type APICall
- type FakeAPI
- type FakeDocker
- func (f *FakeDocker) Calls() [][]string
- func (f *FakeDocker) CallsOf(verb string) [][]string
- func (f *FakeDocker) Container(name string) (fakeRec, bool)
- func (f *FakeDocker) Created(name string) bool
- func (f *FakeDocker) DockerHosts() []string
- func (f *FakeDocker) EnvFile(name string) (path, mode, body string, ok bool)
- func (f *FakeDocker) Exists(name string) bool
- func (f *FakeDocker) HoldRecord()
- func (f *FakeDocker) Plant(name string, labels map[string]string) string
- func (f *FakeDocker) ReleaseAllRecords()
- func (f *FakeDocker) ReleaseRecord(name string)
- func (f *FakeDocker) RemoveRecordGates()
- func (f *FakeDocker) Removed(name string) bool
- func (f *FakeDocker) RemovedBy() []string
- func (f *FakeDocker) Running(name string) bool
- type H
- func (h *H) Atoi(s string) int
- func (h *H) FakeDocker() *FakeDocker
- func (h *H) Hold(env []string, runArgs ...string) *Holder
- func (h *H) HostConfig(body string)
- func (h *H) Origin(name string) string
- func (h *H) Plugin(typ string) (path, sum string)
- func (h *H) PluginFrom(typ, src string) (path, sum string)
- func (h *H) Repo(name string, files map[string]string) string
- func (h *H) Run(args ...string) Result
- func (h *H) RunWith(env []string, args ...string) Result
- func (h *H) Seam(line string)
- func (h *H) SetSeam(key, value string)
- func (h *H) Start(args ...string) *Proc
- func (h *H) StartFakeAPI(bin string) *FakeAPI
- func (h *H) StartWith(env []string, args ...string) *Proc
- func (h *H) Track(pid int)
- func (h *H) Until(cond func() bool, d time.Duration)
- func (h *H) Write(path, body string, mode os.FileMode)
- type Holder
- type Proc
- type Result
Constants ¶
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 ¶
var Bin string
Bin is the bitc binary under test, set by the conformance TestMain.
var RefPlugin, RefFakeAPI string
RefPlugin and RefFakeAPI are the built reference plugin and fake API (BuildReference).
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"`.
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
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 ¶
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 ¶
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 ModuleRoot ¶ added in v0.1.6
ModuleRoot is the module root, found from the working directory (a test runs in its package).
func ReadEnvFile ¶
ReadEnvFile parses `env` output.
func WithRemoteFlag ¶ added in v0.1.1
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 ¶
Behave is POST /__bitc/behave: the behaviour the fake shows to instances created from now on.
func (*FakeAPI) Calls ¶
Calls is GET /__bitc/calls: every API call in order, the attach call marked.
func (*FakeAPI) Seed ¶
Seed lists an instance with no process (optional part of the contract); it returns its id.
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 (*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 ¶
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 ¶
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) Plugin ¶
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 ¶
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) SetSeam ¶
SetSeam sets one [test] key, replacing an earlier line for it, and rewrites the host file.
func (*H) StartFakeAPI ¶
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.