testhome

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0 modules, 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 keeps tests out of the real home folder.

komando reads and writes under the home folder in many places: its own data in ~/.komando, and ~/.ssh, ~/.aws, ~/.kube and the like. A test that moves only komando's folder (KOMANDO_HOME) still has the real home behind os.UserHomeDir, and one such test once wrote over a person's private key. So every package whose code names a home folder starts its tests with Use, which gives the whole test binary a throwaway home.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir() string

Dir is the throwaway home folder ("" before Use).

func Path

func Path(t TB, p string) string

Path returns p when it lies in the throwaway home or in the system's temp folder (t.TempDir), and fails the test otherwise. A test that writes to a path built from the home folder passes the path through it, so a test started without Use cannot reach the real home.

func Real

func Real() string

Real is the home folder the tests were started with. Nothing may be written there; tests use it only to say "not this one".

func Use

func Use() (done func())

Use points HOME, USERPROFILE, APPDATA, LOCALAPPDATA and the XDG folders at one new, empty folder for the rest of the test binary, and returns the function that removes it. Call it first in TestMain:

func TestMain(m *testing.M) {
	done := testhome.Use()
	code := m.Run()
	done()
	os.Exit(code)
}

A test binary that a test started itself keeps its parent's folder and removes nothing. The Go tool keeps the caches and the toolchain it had (they live under the real home), so a test may still run `go`.

The tests also run as a script, whoever starts them: for an AI agent komando takes the home folder from the system's user database, which no variable moves (store.UserHome), so the variables an agent's shell sets are taken out. A test about agents sets one itself, and then answers for store.AccountHome too.

Types

type TB

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

TB is the part of testing.TB that Path needs.

Jump to

Keyboard shortcuts

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