Documentation
¶
Overview ¶
Package testutil provides utilities for testing dodot components.
This package follows the testing guidelines defined in docs/testing/guide.txxt and provides the infrastructure described in docs/testing/infrastructure-utils-setup.txxt.
Key components:
- TestEnvironment: Core test orchestrator with isolation and cleanup
- MemoryFS: In-memory filesystem implementation for fast, isolated tests
- MockDataStore: Mock state management without filesystem operations
- PackBuilder: Declarative pack setup builder
Usage guidelines:
- 95% of tests should use EnvMemoryOnly for speed and isolation
- Only pkg/datastore tests should use real filesystem operations
- All test data should be defined inline, not in external files
- Each test should be completely isolated with no shared state
Package testutil provides testing utilities
Index ¶
- func GetTestChecksum(content string) string
- type EnvType
- type FileTree
- type MemoryFS
- func (m *MemoryFS) Chdir(dir string) error
- func (m *MemoryFS) Getwd() (string, error)
- func (m *MemoryFS) Lstat(name string) (os.FileInfo, error)
- func (m *MemoryFS) MkdirAll(path string, perm os.FileMode) error
- func (m *MemoryFS) Open(name string) (fs.File, error)
- func (m *MemoryFS) ReadDir(name string) ([]fs.DirEntry, error)
- func (m *MemoryFS) ReadFile(name string) ([]byte, error)
- func (m *MemoryFS) Readlink(name string) (string, error)
- func (m *MemoryFS) Remove(name string) error
- func (m *MemoryFS) RemoveAll(path string) error
- func (m *MemoryFS) Rename(oldpath, newpath string) error
- func (m *MemoryFS) Stat(name string) (os.FileInfo, error)
- func (m *MemoryFS) Stats() (reads, writes int)
- func (m *MemoryFS) Symlink(target, link string) error
- func (m *MemoryFS) WithError(path string, err error) *MemoryFS
- func (m *MemoryFS) WriteFile(name string, data []byte, perm os.FileMode) error
- type MockDataStore
- func (m *MockDataStore) CreateDataLink(pack, handlerName, sourceFile string) (string, error)
- func (m *MockDataStore) CreateUserLink(datastorePath, userPath string) error
- func (m *MockDataStore) GetCalls() []string
- func (m *MockDataStore) GetDataLinks() map[string]string
- func (m *MockDataStore) GetSentinels() map[string]bool
- func (m *MockDataStore) GetUserLinks() map[string]string
- func (m *MockDataStore) HasHandlerState(pack, handlerName string) (bool, error)
- func (m *MockDataStore) HasSentinel(pack, handlerName, sentinel string) (bool, error)
- func (m *MockDataStore) ListHandlerSentinels(pack, handlerName string) ([]string, error)
- func (m *MockDataStore) ListPackHandlers(pack string) ([]string, error)
- func (m *MockDataStore) RemoveState(pack, handlerName string) error
- func (m *MockDataStore) Reset()
- func (m *MockDataStore) RunAndRecord(pack, handlerName, command, sentinel string) error
- func (m *MockDataStore) SetSentinel(pack, handlerName, sentinel string, exists bool)
- func (m *MockDataStore) WithDataLink(pack, handler, source, datastorePath string) *MockDataStore
- func (m *MockDataStore) WithError(method string, err error) *MockDataStore
- func (m *MockDataStore) WithSentinel(pack, handler, sentinel string, exists bool) *MockDataStore
- func (m *MockDataStore) WithUserLink(userPath, datastorePath string) *MockDataStore
- type MockPathResolver
- func (m *MockPathResolver) CacheDir() string
- func (m *MockPathResolver) ConfigDir() string
- func (m *MockPathResolver) DataDir() string
- func (m *MockPathResolver) DotfilesRoot() string
- func (m *MockPathResolver) Home() string
- func (m *MockPathResolver) MapPackFileToSystem(pack *types.Pack, relPath string) string
- func (m *MockPathResolver) PackHandlerDir(packName, handlerName string) string
- func (m *MockPathResolver) StateDir() string
- func (m *MockPathResolver) WithDotfilesRoot(path string) *MockPathResolver
- type MockSimpleDataStore
- func (m *MockSimpleDataStore) CreateDataLink(pack, handlerName, sourceFile string) (string, error)
- func (m *MockSimpleDataStore) CreateUserLink(datastorePath, userPath string) error
- func (m *MockSimpleDataStore) GetCommands() map[string]string
- func (m *MockSimpleDataStore) GetDataLinks() map[string]string
- func (m *MockSimpleDataStore) GetSentinels() map[string]bool
- func (m *MockSimpleDataStore) GetUserLinks() map[string]string
- func (m *MockSimpleDataStore) HasHandlerState(pack, handlerName string) (bool, error)
- func (m *MockSimpleDataStore) HasSentinel(pack, handlerName, sentinel string) (bool, error)
- func (m *MockSimpleDataStore) ListHandlerSentinels(pack, handlerName string) ([]string, error)
- func (m *MockSimpleDataStore) ListPackHandlers(pack string) ([]string, error)
- func (m *MockSimpleDataStore) RemoveState(pack, handlerName string) error
- func (m *MockSimpleDataStore) RunAndRecord(pack, handlerName, command, sentinel string) error
- func (m *MockSimpleDataStore) SetSentinel(pack, handlerName, sentinel string, exists bool)
- type PackConfig
- type Rule
- type TestEnvironment
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetTestChecksum ¶ added in v0.3.0
GetTestChecksum calculates a SHA256 checksum for test content This is used in tests to generate predictable checksums
Types ¶
type FileTree ¶ added in v0.3.0
type FileTree map[string]interface{}
FileTree represents a directory structure for testing
type MemoryFS ¶ added in v0.3.0
type MemoryFS struct {
// contains filtered or unexported fields
}
MemoryFS implements types.FS interface with in-memory storage
func NewMemoryFS ¶ added in v0.3.0
func NewMemoryFS() *MemoryFS
NewMemoryFS creates a new in-memory filesystem
type MockDataStore ¶ added in v0.3.0
type MockDataStore struct {
// contains filtered or unexported fields
}
MockDataStore is a mock implementation of datastore.DataStore for testing
func NewMockDataStore ¶ added in v0.3.0
func NewMockDataStore() *MockDataStore
NewMockDataStore creates a new mock DataStore
func (*MockDataStore) CreateDataLink ¶ added in v0.3.0
func (m *MockDataStore) CreateDataLink(pack, handlerName, sourceFile string) (string, error)
CreateDataLink creates an intermediate symlink in the datastore
func (*MockDataStore) CreateUserLink ¶ added in v0.3.0
func (m *MockDataStore) CreateUserLink(datastorePath, userPath string) error
CreateUserLink creates a user-facing symlink
func (*MockDataStore) GetCalls ¶ added in v0.3.0
func (m *MockDataStore) GetCalls() []string
GetCalls returns all recorded method calls
func (*MockDataStore) GetDataLinks ¶ added in v0.3.0
func (m *MockDataStore) GetDataLinks() map[string]string
GetDataLinks returns all data links (for testing)
func (*MockDataStore) GetSentinels ¶ added in v0.3.0
func (m *MockDataStore) GetSentinels() map[string]bool
GetSentinels returns all sentinels (for testing)
func (*MockDataStore) GetUserLinks ¶ added in v0.3.0
func (m *MockDataStore) GetUserLinks() map[string]string
GetUserLinks returns all user links (for testing)
func (*MockDataStore) HasHandlerState ¶ added in v0.3.0
func (m *MockDataStore) HasHandlerState(pack, handlerName string) (bool, error)
HasHandlerState checks if any state exists for a handler in a pack
func (*MockDataStore) HasSentinel ¶ added in v0.3.0
func (m *MockDataStore) HasSentinel(pack, handlerName, sentinel string) (bool, error)
HasSentinel checks if an operation has been completed
func (*MockDataStore) ListHandlerSentinels ¶ added in v0.3.0
func (m *MockDataStore) ListHandlerSentinels(pack, handlerName string) ([]string, error)
ListHandlerSentinels returns all sentinel files for a specific handler in a pack
func (*MockDataStore) ListPackHandlers ¶ added in v0.3.0
func (m *MockDataStore) ListPackHandlers(pack string) ([]string, error)
ListPackHandlers returns a list of all handlers that have state for a given pack
func (*MockDataStore) RemoveState ¶ added in v0.3.0
func (m *MockDataStore) RemoveState(pack, handlerName string) error
RemoveState removes all state for a handler in a pack
func (*MockDataStore) Reset ¶ added in v0.3.0
func (m *MockDataStore) Reset()
Reset clears all state
func (*MockDataStore) RunAndRecord ¶ added in v0.3.0
func (m *MockDataStore) RunAndRecord(pack, handlerName, command, sentinel string) error
RunAndRecord executes a command and records completion with a sentinel
func (*MockDataStore) SetSentinel ¶ added in v0.3.0
func (m *MockDataStore) SetSentinel(pack, handlerName, sentinel string, exists bool)
SetSentinel sets a sentinel value for testing
func (*MockDataStore) WithDataLink ¶ added in v0.3.0
func (m *MockDataStore) WithDataLink(pack, handler, source, datastorePath string) *MockDataStore
WithDataLink pre-configures a data link
func (*MockDataStore) WithError ¶ added in v0.3.0
func (m *MockDataStore) WithError(method string, err error) *MockDataStore
WithError configures the mock to return an error for a specific method
func (*MockDataStore) WithSentinel ¶ added in v0.3.0
func (m *MockDataStore) WithSentinel(pack, handler, sentinel string, exists bool) *MockDataStore
WithSentinel pre-configures a sentinel
func (*MockDataStore) WithUserLink ¶ added in v0.3.0
func (m *MockDataStore) WithUserLink(userPath, datastorePath string) *MockDataStore
WithUserLink pre-configures a user link
type MockPathResolver ¶ added in v0.3.0
type MockPathResolver struct {
// contains filtered or unexported fields
}
MockPathResolver provides mock path resolution for testing
func NewMockPathResolver ¶ added in v0.3.0
func NewMockPathResolver(home, xdgConfig, xdgData string) *MockPathResolver
NewMockPathResolver creates a new mock path resolver
func (*MockPathResolver) CacheDir ¶ added in v0.3.0
func (m *MockPathResolver) CacheDir() string
CacheDir returns the XDG cache directory
func (*MockPathResolver) ConfigDir ¶ added in v0.3.0
func (m *MockPathResolver) ConfigDir() string
ConfigDir returns the XDG config directory
func (*MockPathResolver) DataDir ¶ added in v0.3.0
func (m *MockPathResolver) DataDir() string
DataDir returns the XDG data directory
func (*MockPathResolver) DotfilesRoot ¶ added in v0.3.0
func (m *MockPathResolver) DotfilesRoot() string
DotfilesRoot returns the dotfiles root directory
func (*MockPathResolver) Home ¶ added in v0.3.0
func (m *MockPathResolver) Home() string
Home returns the home directory path
func (*MockPathResolver) MapPackFileToSystem ¶ added in v0.3.0
func (m *MockPathResolver) MapPackFileToSystem(pack *types.Pack, relPath string) string
MapPackFileToSystem maps a pack file to its system location
func (*MockPathResolver) PackHandlerDir ¶ added in v0.3.0
func (m *MockPathResolver) PackHandlerDir(packName, handlerName string) string
PackHandlerDir returns the directory for a pack's handler state
func (*MockPathResolver) StateDir ¶ added in v0.3.0
func (m *MockPathResolver) StateDir() string
StateDir returns the XDG state directory
func (*MockPathResolver) WithDotfilesRoot ¶ added in v0.3.0
func (m *MockPathResolver) WithDotfilesRoot(path string) *MockPathResolver
WithDotfilesRoot sets a custom dotfiles root
type MockSimpleDataStore ¶ added in v0.3.0
type MockSimpleDataStore struct {
// contains filtered or unexported fields
}
MockSimpleDataStore provides a simple mock DataStore for testing
func NewMockSimpleDataStore ¶ added in v0.3.0
func NewMockSimpleDataStore(fs types.FS) *MockSimpleDataStore
NewMockSimpleDataStore creates a new mock datastore
func (*MockSimpleDataStore) CreateDataLink ¶ added in v0.3.0
func (m *MockSimpleDataStore) CreateDataLink(pack, handlerName, sourceFile string) (string, error)
func (*MockSimpleDataStore) CreateUserLink ¶ added in v0.3.0
func (m *MockSimpleDataStore) CreateUserLink(datastorePath, userPath string) error
func (*MockSimpleDataStore) GetCommands ¶ added in v0.3.0
func (m *MockSimpleDataStore) GetCommands() map[string]string
func (*MockSimpleDataStore) GetDataLinks ¶ added in v0.3.0
func (m *MockSimpleDataStore) GetDataLinks() map[string]string
Helper methods for testing
func (*MockSimpleDataStore) GetSentinels ¶ added in v0.3.0
func (m *MockSimpleDataStore) GetSentinels() map[string]bool
func (*MockSimpleDataStore) GetUserLinks ¶ added in v0.3.0
func (m *MockSimpleDataStore) GetUserLinks() map[string]string
func (*MockSimpleDataStore) HasHandlerState ¶ added in v0.3.0
func (m *MockSimpleDataStore) HasHandlerState(pack, handlerName string) (bool, error)
HasHandlerState checks if any state exists for a handler in a pack
func (*MockSimpleDataStore) HasSentinel ¶ added in v0.3.0
func (m *MockSimpleDataStore) HasSentinel(pack, handlerName, sentinel string) (bool, error)
func (*MockSimpleDataStore) ListHandlerSentinels ¶ added in v0.3.0
func (m *MockSimpleDataStore) ListHandlerSentinels(pack, handlerName string) ([]string, error)
ListHandlerSentinels returns all sentinel files for a specific handler in a pack
func (*MockSimpleDataStore) ListPackHandlers ¶ added in v0.3.0
func (m *MockSimpleDataStore) ListPackHandlers(pack string) ([]string, error)
ListPackHandlers returns a list of all handlers that have state for a given pack
func (*MockSimpleDataStore) RemoveState ¶ added in v0.3.0
func (m *MockSimpleDataStore) RemoveState(pack, handlerName string) error
func (*MockSimpleDataStore) RunAndRecord ¶ added in v0.3.0
func (m *MockSimpleDataStore) RunAndRecord(pack, handlerName, command, sentinel string) error
func (*MockSimpleDataStore) SetSentinel ¶ added in v0.3.0
func (m *MockSimpleDataStore) SetSentinel(pack, handlerName, sentinel string, exists bool)
SetSentinel sets a sentinel value for testing
type PackConfig ¶ added in v0.3.0
type PackConfig struct {
Files map[string]string // Path -> Content
Rules []Rule // Rules configuration
}
PackConfig defines configuration for a test pack
func ShellPack ¶ added in v0.3.0
func ShellPack() PackConfig
ShellPack returns a pre-configured shell pack
func ToolsPack ¶ added in v0.3.0
func ToolsPack() PackConfig
ToolsPack returns a pre-configured tools pack
type Rule ¶ added in v0.3.0
type Rule struct {
Type string // "filename", "directory", etc.
Pattern string
Handler string
Options map[string]interface{}
}
Rule represents a test rule configuration
type TestEnvironment ¶ added in v0.1.1
type TestEnvironment struct {
// Core paths
DotfilesRoot string
HomeDir string
XDGData string
// Core dependencies
DataStore datastore.DataStore
FS types.FS
Paths types.Pather
// Environment type
Type EnvType
// contains filtered or unexported fields
}
TestEnvironment provides a complete test environment with all dependencies
func NewTestEnvironment ¶ added in v0.1.1
func NewTestEnvironment(t *testing.T, envType EnvType) *TestEnvironment
NewTestEnvironment creates a new test environment
func (*TestEnvironment) Cleanup ¶ added in v0.1.1
func (env *TestEnvironment) Cleanup()
Cleanup performs environment cleanup
func (*TestEnvironment) SetupPack ¶ added in v0.3.0
func (env *TestEnvironment) SetupPack(name string, config PackConfig) types.Pack
SetupPack creates a test pack with the given configuration
func (*TestEnvironment) WithFileTree ¶ added in v0.3.0
func (env *TestEnvironment) WithFileTree(tree FileTree)
WithFileTree creates a complete file tree structure