Documentation
¶
Overview ¶
Package testenv establishes process-wide isolation for test binaries that shell out to tmux.
Any package whose tests reach tmux — directly, or indirectly through internal/tty — must isolate, because the alternative is that `go test ./...` operates on the developer's own tmux server. That is not a hypothetical: td-4d99ae found 66 orphaned control-mode clients and 18 orphaned servers accumulated over about a week of test runs, which drove the real server past its file-descriptor limit and made every Sidecar tmux call intermittently fail. td-8d18de is the same lesson learned the harder way.
TMUX_TMPDIR relocates tmux's default socket, so tmux resolves to a private server for this process and every tmux child it spawns. Nothing an isolated suite does can reach the developer's sessions, whatever session name a future test happens to pick.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsolateTmux ¶
IsolateTmux points every tmux command this process runs at a throwaway server and returns the socket path plus a teardown.
Teardown kills the server by explicit socket path rather than running a bare `tmux kill-server`. A bare kill-server trusts the environment to still be pointing somewhere private; if anything has disturbed TMUX_TMPDIR by then it destroys the developer's own server and every session on it. -S names the file we created, so the blast radius cannot leave this temp dir.
The returned teardown is safe to call more than once and from more than one goroutine.
func Main ¶
Main runs m with tmux isolated, tears down, and returns the exit code. Callers do:
func TestMain(m *testing.M) { os.Exit(testenv.Main(m)) }
Teardown also runs on SIGINT/SIGTERM, so an interrupted run does not leak. It cannot run when the binary dies by panic or by `go test` timeout — Go exits those paths without unwinding TestMain — which is why teardown leaves a reachable socket behind rather than an orphan with no path, and why `make reap-test-tmux` exists.
func OnSignal ¶
func OnSignal(fn func()) (stop func())
OnSignal runs fn if the process is interrupted, then restores the default disposition and re-raises so the exit status still reflects the signal.
Packages that drive TestMain themselves — because they isolate a second axis as well — should call this alongside IsolateTmux, so an interrupted run gets the same cleanup Main provides.
The returned stop waits for an in-flight handler to finish, so a signal arriving exactly as m.Run returns cannot leave teardown running concurrently with the caller's own teardown call.
func RequireTmux ¶ added in v1.12.0
RequireTmux keeps real-tmux tests convenient in an ordinary checkout while making the compatibility matrix fail closed. A missing prerequisite may be a local skip, but it is a broken compatibility proof when the driver sets SIDECAR_REQUIRE_TMUX_COMPAT=1.
func SocketPath ¶
SocketPath is where tmux puts its default socket under a given TMUX_TMPDIR.
func TmuxCompatibilityRequired ¶ added in v1.12.0
func TmuxCompatibilityRequired() bool
TmuxCompatibilityRequired reports whether skips that would weaken the tmux matrix contract must instead fail. It is for integration setup failures that happen after RequireTmux has found the binary.
Types ¶
This section is empty.