testhome

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 18 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 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

View Source
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

func Main(run func() int) int

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 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

func RequireNoHostSession(t testing.TB)

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

func Run(m *testing.M)

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

func WithoutSession(environ []string) []string

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.

Jump to

Keyboard shortcuts

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