Documentation
¶
Index ¶
- func AssertFileContains(t *testing.T, filePath, expected string)
- func AssertFileNotContains(t *testing.T, filePath, unexpected string)
- func ChecksumAwareDownloadFn(t *testing.T) func(context.Context, string, string, downloader.RetryConfig) error
- func CreateGlobalConfigFile(t *testing.T, configDir string, content string) string
- func CreateGlobalConfigTemplate(t *testing.T, templatesDir string)
- func CreateShellConfigTemplate(t *testing.T, templatesDir string, content string)
- func InitLogger()
- func IsolateXDGDirs(t *testing.T) string
- func SetupTestDirs(t *testing.T) (appDir, configDir, templatesDir, devgetaConfigDir string)
- func VerifyNoRealCommands(t *testing.T, mockBase *commands.MockBaseCommand)
- func VerifyNoRealConfigChanges(t *testing.T)
- type MockApp
- type PathsCleanup
- type TestConfig
- type TestPaths
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertFileContains ¶
AssertFileContains verifies that a file contains expected content
func AssertFileNotContains ¶
AssertFileNotContains verifies that a file does not contain specific content
func ChecksumAwareDownloadFn ¶
func ChecksumAwareDownloadFn( t *testing.T, ) func(context.Context, string, string, downloader.RetryConfig) error
ChecksumAwareDownloadFn returns a downloadFn for commands.InstallGitHubBinary tests: it writes fake archive bytes to the archive destination and a matching sha256sum-format checksums file to the checksums destination, so the helper's mandatory SHA-256 verification passes with zero network access. The checksums destination is recognized by the "-checksums.txt" suffix InstallGitHubBinary uses; the archive is always requested first, so its file name is known by the time the checksums file is written.
func CreateGlobalConfigFile ¶
CreateGlobalConfigFile creates a global_config.yaml file with specified content
func CreateGlobalConfigTemplate ¶
CreateGlobalConfigTemplate creates a basic global_config.yaml template
func CreateShellConfigTemplate ¶
CreateShellConfigTemplate creates a basic devgeta.zsh.tmpl template
func InitLogger ¶
func InitLogger()
InitLogger initializes the logger for tests Call this in your init() function
func IsolateXDGDirs ¶
IsolateXDGDirs redirects all XDG base directories to a temp directory. This prevents tests from reading, writing, or deleting real user data in ~/.local/share, ~/.local/state, ~/.cache, or ~/.config.
CRITICAL: Any test that calls Uninstall(), ForceInstall(), or any code path that uses paths.GetDataDir, paths.GetStateDir, paths.GetCacheDir, or paths.GetConfigDir MUST call this helper first.
Usage:
testutil.IsolateXDGDirs(t) // XDG dirs now point to temp directories; restored automatically after test
func SetupTestDirs ¶
SetupTestDirs creates a complete test directory structure Returns paths to key directories
func VerifyNoRealCommands ¶
func VerifyNoRealCommands(t *testing.T, mockBase *commands.MockBaseCommand)
VerifyNoRealCommands verifies that no real commands were executed
func VerifyNoRealConfigChanges ¶
VerifyNoRealConfigChanges verifies that no real configuration files were modified
Types ¶
type MockApp ¶
type MockApp struct {
Cmd *commands.MockCommand
Base *commands.MockBaseCommand
}
NewMockApp creates a mock app instance with isolated mocks This ensures tests don't execute real commands
type PathsCleanup ¶
type PathsCleanup func()
PathsCleanup is a function that restores original paths
func SetupIsolatedPaths ¶
func SetupIsolatedPaths(t *testing.T) PathsCleanup
SetupIsolatedPaths overrides global path variables with test-specific paths Returns a cleanup function to restore original paths
This ensures tests don't: - Read from real configuration directories - Write to real configuration directories - Execute real system commands - Modify the user's actual .zshrc or shell configuration
Usage:
cleanup := testutil.SetupIsolatedPaths(t) defer cleanup()
func SetupTestEnvironment ¶
func SetupTestEnvironment(t *testing.T) (appDir, configDir, templatesDir string, cleanup PathsCleanup)
SetupTestEnvironment creates isolated paths and directory structure Returns paths and cleanup function
This is the recommended way to start any test that touches configuration ¶
Usage:
appDir, configDir, templatesDir, cleanup := testutil.SetupTestEnvironment(t) defer cleanup()
type TestConfig ¶
type TestConfig struct {
AppDir string
ConfigDir string
TemplatesDir string
Cleanup PathsCleanup
MockApp *MockApp
ConfigPath string
ZshConfigPath string
}
TestConfig holds common test configuration
func SetupCompleteTest ¶
func SetupCompleteTest(t *testing.T) *TestConfig
SetupCompleteTest creates a complete test environment with all common setup This is the most convenient function for testing apps that use configuration
Usage:
tc := testutil.SetupCompleteTest(t) defer tc.Cleanup() // Use tc.MockApp for mock instances // Use tc.AppDir, tc.ConfigDir, etc. for paths