Documentation
¶
Overview ¶
Package testutil provides utilities for creating isolated, hermetic test environments
Index ¶
- func AssertPathsEqual(t *testing.T, expected, actual, message string)
- func AutoCleanupTestContainers() error
- func CanonicalPath(t *testing.T, path string) string
- func CleanupAllTestContainers() error
- func CleanupTestContainers(isolationPrefix string) error
- func RobustRemoveAll(t *testing.T, path string) error
- func SetupIsolatedTest(t *testing.T) (homeDir, workspaceDir string, cleanup func())
- func WithIsolatedHome(t *testing.T) string
- func WithIsolatedWorkspace(t *testing.T) (homeDir, workspaceDir string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertPathsEqual ¶
AssertPathsEqual compares two paths after canonicalizing them to handle symlink differences across operating systems.
Usage:
testutil.AssertPathsEqual(t, expectedPath, actualPath, "project root should match")
func AutoCleanupTestContainers ¶
func AutoCleanupTestContainers() error
AutoCleanupTestContainers automatically cleans up test containers based on the current REACTOR_ISOLATION_PREFIX environment variable. This should be called in test cleanup functions.
func CanonicalPath ¶
CanonicalPath resolves symlinks and returns the canonical absolute path. This is useful for path comparisons in tests that might encounter symlink differences between different operating systems (e.g., /var vs /private/var on macOS).
Usage:
expected := testutil.CanonicalPath(t, expectedPath) actual := testutil.CanonicalPath(t, actualPath) assert.Equal(t, expected, actual)
func CleanupAllTestContainers ¶
func CleanupAllTestContainers() error
CleanupAllTestContainers cleans up all test containers that match common test prefixes. This is useful for cleaning up accumulated state from previous failed test runs.
func CleanupTestContainers ¶
CleanupTestContainers provides comprehensive cleanup for reactor containers created during integration tests. This function implements the self-cleaning container approach to resolve permission issues where containers create files with different ownership that Go test cleanup cannot remove.
func RobustRemoveAll ¶
RobustRemoveAll attempts standard removal first, falling back to Docker-based force removal if permission errors occur. This is the primary cleanup function that should be used for test directories that may contain Docker-created files.
func SetupIsolatedTest ¶
SetupIsolatedTest provides complete test isolation including HOME directory, workspace directory, and robust cleanup for Docker-created files. This is the most comprehensive test isolation helper.
The cleanup function now uses RobustRemoveAll which handles permission issues caused by Docker containers creating files with different ownership.
Usage:
func TestSomething(t *testing.T) {
homeDir, workspaceDir, cleanup := testutil.SetupIsolatedTest(t)
defer cleanup() // Recommended for tests that use Docker
// Change to workspace directory for the test
originalWD, _ := os.Getwd()
os.Chdir(workspaceDir)
defer os.Chdir(originalWD)
}
func WithIsolatedHome ¶
WithIsolatedHome creates a temporary home directory and sets the HOME environment variable for the duration of the test. This ensures tests run in a clean, isolated environment without depending on the actual user's home directory.
Usage:
func TestSomething(t *testing.T) {
testutil.WithIsolatedHome(t)
// Test code that depends on HOME directory
}
func WithIsolatedWorkspace ¶
WithIsolatedWorkspace creates both an isolated home directory and a temporary workspace directory for tests that need both. Returns both paths.
Usage:
func TestSomething(t *testing.T) {
homeDir, workspaceDir := testutil.WithIsolatedWorkspace(t)
// Test code that needs both home and workspace isolation
}
Types ¶
This section is empty.