Documentation
¶
Overview ¶
Package testhome runs a test binary against a scratch home and no session but its own, so no test, and no application or daemon it starts, reads or writes the real user's files or reaches the session of whoever runs it: the session bus, the system bus, the compositor, the sound server. A TestMain calls Run (or Main, around work of its own), and one test of the package calls RequireNoHostSession, which fails where a host endpoint is still within reach.
Index ¶
Constants ¶
const SessionEnv = "LYS_TEST_SESSION"
SessionEnv is how a recipe that boots a session for a test run (a headless compositor, a VM's desktop) names it to the tests: the session's runtime directory. Main then leaves that session in place, and RequireNoHostSession holds every endpoint to it, wherever the directory lies: in a VM it is /run/user/<uid>, which on a developer's machine is the desktop's.
Variables ¶
This section is empty.
Functions ¶
func Main ¶
Main is Run for a TestMain with work of its own around the tests: it isolates the process, calls run, and returns its code.
Isolating points HOME and the XDG per-user directories under a fresh temp directory, and the system bus at a socket there that nothing serves: a test that needs a system bus starts its own and points the process at it (dbustest's UseAsSystemBus). Outside a headless run it also unsets every variable that advertises a running compositor, display, desktop or media server, and points the runtime directory, which it creates with mode 0700, the session bus and the sound server at sockets under the temp directory, where only a test's own fake can be. In a headless run (wltest.HeadlessEnv), or with a session a recipe named (SessionEnv), the session in the environment is the one the recipe booted for the tests, and stays: only the system bus and the sound server are pinned, the latter to the recipe's runtime directory, and a session bus the recipe did not name, to a socket under the temp directory, so that no client guesses one. The home and every temporary directory lie on the tmpfs at /dev/shm, which must be one: TMPDIR, and GOTMPDIR, which testing's TempDir and the go command's work directories take before TMPDIR. The go command's caches and configuration, whose defaults lie under the home that moved, stay where they were, so a go build a test runs starts warm.
A test binary started by an isolated test (a helper process, the binary run again as the program under test) runs as it is: its environment is the one its parent made for it.
func RequireNoHostSession ¶
RequireNoHostSession fails t when the test process could reach the session or the system bus of the host it runs on: when the runtime directory, the session bus, the system bus or the sound server it would dial is unset, leaving a client to guess the host's; when one of them, the Wayland display or a media server's socket lies in the host's runtime directory; when a system bus answers at all, which only a bus the calling test itself started may; and, outside a headless run, when a display is named or a session bus, a compositor or a sound server answers. Every package whose tests build applications or dial a bus calls it from a test of its own, under a TestMain that calls Run.
Where a recipe named the session it booted (SessionEnv), the process is held to exactly that session instead: the runtime directory is the one named, and the session bus, the system bus, the sound server, an absolute Wayland display and a media server's socket each lie in it or in the test home Main made. The system bus still answers to none.
func Run ¶
Run isolates the test binary in a fresh temp directory, runs the tests, removes the directory, and exits with their code. Call it from TestMain. See Main for what isolating does.
func WithoutSession ¶
WithoutSession returns environ, in os.Environ's KEY=value form, minus every variable that advertises a running compositor, display, desktop or media server, for a child a test starts as a session of its own.
Types ¶
This section is empty.