homeenv

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package homeenv isolates a test binary from the real developer machine's persistent boid state — $HOME, the XDG base directories, and the docker engine — and lets a test assert that the isolation is actually in place.

This exists as a shared package rather than a copy-pasted TestMain body because boid resolves several persistent roots (workspace homes, the daemon's ~/.config/boid, and the docker engine holding workspace HOME volumes) from the environment whenever the corresponding *Runner field is left empty, and a bare `dispatcher.Runner{}` is the standard minimal test wiring across several packages — one shared list keeps every consumer's isolation in sync instead of drifting per-package.

Everything here is test-only. It is imported from _test.go files and from testutil (itself test-only — it takes *testing.T), so it never links into the shipped binary despite importing "testing".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertIsolated

func AssertIsolated(t *testing.T)

AssertIsolated fails t when Unisolated reports anything — i.e. when the package under test has no TestMain calling Run/Isolate, or gained a new variable the lists above cover but that TestMain does not.

Call it from a test in every package whose suite can reach a code path that resolves a boid data/config root, or a docker engine, from the environment. Without it, losing the TestMain is silent: the suite keeps passing, it just starts writing into (and, via init.sh, executing code from) the real user's boid installation — and deleting named volumes off their real engine.

func Isolate

func Isolate() (cleanup func(), err error)

Isolate points HOME, the XDG base directories and DOCKER_HOST at a fresh temp directory (clearing the remaining docker transport variables) and returns a function that removes it. Callers that use Isolate directly (rather than Run) are responsible for calling the returned cleanup — and for not calling os.Exit before it runs.

func Run

func Run(m *testing.M) int

Run is the whole body of a TestMain that needs nothing else:

func TestMain(m *testing.M) { os.Exit(homeenv.Run(m)) }

It points every isolatedKeys variable at a throwaway temp directory for the lifetime of the test binary, runs the suite, removes the temp directory and returns m.Run's exit code. Individual tests that want their own per-case isolation still call t.Setenv with a fresh t.TempDir(); that overrides this process-wide default for one test and is restored afterwards, so the two layers compose rather than conflict.

A package whose TestMain has other work to do (spawning itself as a helper process, say) should call Isolate directly instead.

func Unisolated

func Unisolated() []string

Unisolated reports every variable this package manages that is still the developer's own: an isolatedKeys entry unchanged since the test binary started, or a clearedKeys entry that is still set. An empty result means Isolate (or Run) has taken effect.

Exported as a plain predicate, rather than living inside AssertIsolated, so the same judgment can be made where there is no *testing.T-shaped assertion to hang off — specifically testutil.NewTestServer, which refuses to boot a daemon into an un-isolated environment. Two copies of this rule would be two places for the key list to drift.

Types

This section is empty.

Jump to

Keyboard shortcuts

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