testtmp

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package testtmp provides temp-dir helpers for tests. It is a dependency-free leaf package so any package's tests can use it without import cycles.

On macOS, Spotlight (mds/mdworker) indexes files under the default TMPDIR (/var/folders/...). When a test writes git object files and then removes the dir, the indexer can still be holding a file, so RemoveAll fails with ENOTEMPTY and the test flakes. These helpers address that two ways: a .metadata_never_index marker (the documented Spotlight exclusion) and a bounded retry on RemoveAll.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RobustTempDir

func RobustTempDir(t *testing.T) string

RobustTempDir is like t.TempDir but excludes its subtree from Spotlight and retries cleanup, so a macOS indexing race can't fail an otherwise-passing test. Cleanup is best-effort and never fails the test.

func RunWithIsolatedTemp

func RunWithIsolatedTemp(m *testing.M) int

RunWithIsolatedTemp runs a package's tests with TMPDIR pointed at a dedicated Spotlight-excluded dir, so every t.TempDir in the package is safe from the macOS indexing race without changing individual tests. Use from TestMain:

func TestMain(m *testing.M) { os.Exit(testtmp.RunWithIsolatedTemp(m)) }

Types

This section is empty.

Jump to

Keyboard shortcuts

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