testbin

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package testbin builds the executables that test harnesses run as child processes, and keeps every such executable and every `go` build temporary on disk, outside the test process's TMPDIR and GOTMPDIR.

Why

Tests may run with TMPDIR and GOTMPDIR pointed at a RAM drive that must hold graph data files only (see CLAUDE.md, "Tests and validation"). A harness that builds a child binary with os.MkdirTemp("", …) and an inherited environment writes the binary, and the child `go` command's work directory, to that RAM drive. This package is the single seam that prevents it:

  • MkdirTemp and TempDir create directories under Root, a fixed location in the user cache directory, never under TMPDIR or GOTMPDIR.
  • Go runs the `go` command with TMPDIR and GOTMPDIR reset, in the child's environment only, to a fresh directory under Root that it removes before returning.

Ownership

The caller owns every directory MkdirTemp returns and must remove it. TempDir registers that removal with the test's Cleanup. A process killed before its cleanup runs leaves its directory under Root.

Concurrency

Every function is safe for concurrent use by multiple goroutines and by multiple processes: each call creates its own uniquely named directory and shares no mutable state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Go

func Go(ctx context.Context, dir string, args ...string) (stdout, stderr []byte, err error)

Go runs `go args...` with working directory dir and returns its standard output and standard error. The child inherits the current environment except TMPDIR and GOTMPDIR, which point to a fresh directory under Root that Go removes before returning, so the `go` command's work files never reach the caller's TMPDIR or GOTMPDIR. The command is killed when ctx is done.

func MkdirTemp

func MkdirTemp(pattern string) (string, error)

MkdirTemp creates a new, uniquely named directory under Root, with pattern interpreted as by os.MkdirTemp, and returns its path. The caller owns the directory and must remove it.

func Root

func Root() (string, error)

Root returns the disk directory under which every testbin directory is created, creating it when absent: <os.UserCacheDir()>/gograph-testbin.

func TempDir

func TempDir(tb TB) string

TempDir creates a directory with MkdirTemp and registers its removal with tb.Cleanup. It fails the test when the directory cannot be created.

Types

type TB

type TB interface {
	Helper()
	Fatalf(format string, args ...any)
	Cleanup(f func())
}

TB is the subset of testing.TB that TempDir uses. It is declared here so that non-test packages may import testbin without linking package testing.

Jump to

Keyboard shortcuts

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