testenv

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package testenv provides environment isolation helpers for tests. This package intentionally has no dependencies on other internal packages to avoid import cycles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultProdDataDir added in v0.35.0

func DefaultProdDataDir() (string, error)

DefaultProdDataDir returns the default production data directory (~/.roborev). This is resolved from the user's home directory, ignoring ROBOREV_DATA_DIR so it always points to the real dir.

func RunIsolatedMain added in v0.37.0

func RunIsolatedMain(m *testing.M) int

RunIsolatedMain provides a standardized TestMain execution wrapper that isolates tests from the production ~/.roborev directory. It safely manages environment variables and preserves the original test exit code.

func SetDataDir

func SetDataDir(t *testing.T) string

SetDataDir sets ROBOREV_DATA_DIR to a temp directory to isolate tests from production ~/.roborev. This is preferred over setting HOME because ROBOREV_DATA_DIR takes precedence in config.DataDir(). Returns the temp directory path. Cleanup is automatic via t.Setenv.

Note: t.Setenv marks the test as incompatible with t.Parallel(), which is appropriate since environment variables are process-global state.

Types

type ProdLogBarrier added in v0.35.0

type ProdLogBarrier struct {
	// contains filtered or unexported fields
}

ProdLogBarrier records the state of production log files before tests run, and provides a Check method that fails hard if any test activity leaked into production logs.

func NewProdLogBarrier added in v0.35.0

func NewProdLogBarrier(prodDataDir string) *ProdLogBarrier

NewProdLogBarrier snapshots the current production data directory state. Call Check() after m.Run() to detect test pollution. prodDataDir should be the default data directory (e.g. ~/.roborev) resolved BEFORE ROBOREV_DATA_DIR is overridden for tests.

func (*ProdLogBarrier) Check added in v0.35.0

func (b *ProdLogBarrier) Check() string

Check verifies no test pollution reached production files. Returns a non-empty error message if pollution is detected.

func (*ProdLogBarrier) Violations added in v0.49.0

func (b *ProdLogBarrier) Violations() []string

Violations reports production data-dir writes caused by the current test process. The returned strings are stable enough for direct test assertions.

Jump to

Keyboard shortcuts

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