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 ¶
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 ¶
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 Run ¶
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.
Types ¶
This section is empty.