testenv

package
v0.1.1046 Latest Latest
Warning

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

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

Documentation

Overview

Package testenv gives a package's tests a home of their own, on every OS: HOME, USERPROFILE (Windows' home), the XDG folders and Windows' APPDATA and LOCALAPPDATA all point into one new temporary folder, the agents' own variables (agentenv.Vars) are cleared, and the keychain tools and agent CLIs on PATH are failing stand-ins, so that no test reads or writes the files of the user running it. Setting HOME alone isn't that: on Windows Go reads the home from USERPROFILE, and a test then meets the real ~/.claude. A package uses it from its TestMain:

func TestMain(m *testing.M) { testenv.Main(m) }

and a test that wants a home of its own sets it with SetHome, never HOME alone. Only tests import it.

Index

Constants

View Source
const (

	// Marker holds the temporary home in the environment. A test binary
	// started again by one of its own tests inherits it, and keeps the
	// environment that test gave it (its fixtures) instead of isolating
	// again; a test that hands such a child an environment of its own
	// passes Marker along.
	Marker = "MAGPIE_TEST_SANDBOX"
)

Variables

This section is empty.

Functions

func Isolate

func Isolate() (string, error)

Isolate points the home and the config, cache and data folders into a new temporary folder, clears the agents' variables, puts the stand-ins first on PATH and gives the folder. It fails when Go would still resolve any of them, or a stand-in's tool, outside that folder.

func Main

func Main(m *testing.M)

Main runs the package's tests in a home of their own and exits with their code.

func Run

func Run(m *testing.M) int

Run is Main for a TestMain with more to set up: it isolates, runs the tests and removes the temporary home, and gives the code to exit with. It runs no test when the home can't be made safe.

func RunIn

func RunIn(m *testing.M, setup func(home string)) int

RunIn is Run with setup called on the temporary home before the tests, for fixtures that live in it.

func SetHome

func SetHome(t testing.TB, dir string)

SetHome makes dir the home for one test, on every OS: HOME, and USERPROFILE, which Go reads on Windows.

Types

This section is empty.

Jump to

Keyboard shortcuts

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