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 SetupCredentialDirectories(t *testing.T, homeDir, account, projectHash string) map[string]string
- 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 using Docker labels. 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 uses Docker labels to identify test containers, providing a more robust cleanup mechanism that doesn't rely on name patterns which can be unreliable.
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 SetupCredentialDirectories ¶ added in v1.1.0
func SetupCredentialDirectories(t *testing.T, homeDir, account, projectHash string) map[string]string
SetupCredentialDirectories creates the reactor credential directory structure for testing account-based credential mounting. Creates directories and test files for all providers under the specified account and project hash.
Usage:
func TestCredentialMounting(t *testing.T) {
homeDir := testutil.WithIsolatedHome(t)
credDirs := testutil.SetupCredentialDirectories(t, homeDir, "work-account", "abc123")
// credDirs contains paths to created credential files for verification
}
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.