Documentation
¶
Overview ¶
Package mocks provides mock implementations for testing.
Index ¶
- type CreateCall
- type ExtractCall
- type InstallCall
- type MockArchiver
- func (m *MockArchiver) Create(destPath, sourceDir string, exclude []string) (int, error)
- func (m *MockArchiver) Extract(zipPath, destDir string) error
- func (m *MockArchiver) List(zipPath string) (map[string]ports.FileInfo, error)
- func (m *MockArchiver) ReadFile(zipPath, filePath, projectName string) (string, error)
- type MockFileSystem
- func (m *MockFileSystem) Create(name string) (*os.File, error)
- func (m *MockFileSystem) MkdirAll(path string, perm os.FileMode) error
- func (m *MockFileSystem) Open(name string) (fs.File, error)
- func (m *MockFileSystem) ReadDir(name string) ([]os.DirEntry, error)
- func (m *MockFileSystem) ReadFile(name string) ([]byte, error)
- func (m *MockFileSystem) Remove(name string) error
- func (m *MockFileSystem) RemoveAll(path string) error
- func (m *MockFileSystem) Rename(oldpath, newpath string) error
- func (m *MockFileSystem) Stat(name string) (os.FileInfo, error)
- func (m *MockFileSystem) Walk(root string, fn ports.WalkFunc) error
- func (m *MockFileSystem) WriteFile(name string, data []byte, perm os.FileMode) error
- type MockGitClient
- type MockLaunchdService
- func (m *MockLaunchdService) Install(execPath, configPath string, hour, minute int) error
- func (m *MockLaunchdService) IsInstalled() bool
- func (m *MockLaunchdService) LogPath() string
- func (m *MockLaunchdService) PlistPath() string
- func (m *MockLaunchdService) Status() string
- func (m *MockLaunchdService) Uninstall() error
- type MockTUIService
- func (m *MockTUIService) ListProjects(cfg *config.Config) ([]ports.TUIProjectInfo, error)
- func (m *MockTUIService) ListVersions(cfg *config.Config, project string) ([]ports.TUIVersionInfo, error)
- func (m *MockTUIService) LoadConfig() (*config.Config, error)
- func (m *MockTUIService) RunBackup(cfg *config.Config, project string) ports.TUIBackupResult
- func (m *MockTUIService) VerifyBackup(cfg *config.Config, project string) error
- type WalkEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreateCall ¶
CreateCall records parameters of a Create call.
type ExtractCall ¶
ExtractCall records parameters of an Extract call.
type InstallCall ¶
InstallCall records parameters of an Install call.
type MockArchiver ¶
type MockArchiver struct {
// CreateCalls records calls to Create
CreateCalls []CreateCall
// ExtractCalls records calls to Extract
ExtractCalls []ExtractCall
// ListResults maps zip paths to file listings
ListResults map[string]map[string]ports.FileInfo
// ReadResults maps "zipPath:filePath" to content
ReadResults map[string]string
// Errors maps method calls to errors
Errors map[string]error
// CreateResult is the default file count to return
CreateResult int
}
MockArchiver implements ports.Archiver for testing.
func NewMockArchiver ¶
func NewMockArchiver() *MockArchiver
NewMockArchiver creates a new mock archiver.
func (*MockArchiver) Create ¶
func (m *MockArchiver) Create(destPath, sourceDir string, exclude []string) (int, error)
Create creates a zip archive of sourceDir at destPath. Returns the number of files archived.
func (*MockArchiver) Extract ¶
func (m *MockArchiver) Extract(zipPath, destDir string) error
Extract extracts a zip archive to destDir.
type MockFileSystem ¶
type MockFileSystem struct {
// Files maps paths to file contents for ReadFile/WriteFile
Files map[string][]byte
// Dirs maps paths to directory entries for ReadDir
Dirs map[string][]os.DirEntry
// Stats maps paths to FileInfo for Stat
Stats map[string]os.FileInfo
// Errors maps paths to errors (for simulating failures)
Errors map[string]error
// WalkEntries contains entries to return during Walk
WalkEntries []WalkEntry
}
MockFileSystem implements ports.FileSystem for testing.
func NewMockFileSystem ¶
func NewMockFileSystem() *MockFileSystem
NewMockFileSystem creates a new mock filesystem.
func (*MockFileSystem) Create ¶
func (m *MockFileSystem) Create(name string) (*os.File, error)
Create creates or truncates the named file.
func (*MockFileSystem) MkdirAll ¶
func (m *MockFileSystem) MkdirAll(path string, perm os.FileMode) error
MkdirAll creates a directory along with any necessary parents.
func (*MockFileSystem) Open ¶
func (m *MockFileSystem) Open(name string) (fs.File, error)
Open opens the named file for reading.
func (*MockFileSystem) ReadDir ¶
func (m *MockFileSystem) ReadDir(name string) ([]os.DirEntry, error)
ReadDir reads the named directory and returns directory entries.
func (*MockFileSystem) ReadFile ¶
func (m *MockFileSystem) ReadFile(name string) ([]byte, error)
ReadFile reads the named file and returns the contents.
func (*MockFileSystem) Remove ¶
func (m *MockFileSystem) Remove(name string) error
Remove removes the named file or empty directory.
func (*MockFileSystem) RemoveAll ¶
func (m *MockFileSystem) RemoveAll(path string) error
RemoveAll removes path and any children it contains.
func (*MockFileSystem) Rename ¶
func (m *MockFileSystem) Rename(oldpath, newpath string) error
Rename renames (moves) oldpath to newpath.
func (*MockFileSystem) Stat ¶
func (m *MockFileSystem) Stat(name string) (os.FileInfo, error)
Stat returns file info for the named file.
type MockGitClient ¶
type MockGitClient struct {
// Heads maps repository paths to HEAD commit hashes
Heads map[string]string
// Repos maps paths to whether they are git repos
Repos map[string]bool
}
MockGitClient implements ports.GitClient for testing.
func NewMockGitClient ¶
func NewMockGitClient() *MockGitClient
NewMockGitClient creates a new mock git client.
func (*MockGitClient) GetHead ¶
func (m *MockGitClient) GetHead(repoPath string) string
GetHead returns the current HEAD commit hash for the repository. Returns empty string if not a git repo or on error.
func (*MockGitClient) IsRepo ¶
func (m *MockGitClient) IsRepo(path string) bool
IsRepo checks if the given path is a git repository.
type MockLaunchdService ¶
type MockLaunchdService struct {
// Installed tracks whether the service is "installed"
Installed bool
// StatusResult is the status to return
StatusResult string
// PlistPathResult is the plist path to return
PlistPathResult string
// LogPathResult is the log path to return
LogPathResult string
// InstallCalls records calls to Install
InstallCalls []InstallCall
// Errors maps method names to errors
Errors map[string]error
}
MockLaunchdService implements ports.LaunchdService for testing.
func NewMockLaunchdService ¶
func NewMockLaunchdService() *MockLaunchdService
NewMockLaunchdService creates a new mock launchd service.
func (*MockLaunchdService) Install ¶
func (m *MockLaunchdService) Install(execPath, configPath string, hour, minute int) error
Install creates the plist file and loads the service.
func (*MockLaunchdService) IsInstalled ¶
func (m *MockLaunchdService) IsInstalled() bool
IsInstalled checks if the service is currently installed.
func (*MockLaunchdService) LogPath ¶
func (m *MockLaunchdService) LogPath() string
LogPath returns the path where logs should be written.
func (*MockLaunchdService) PlistPath ¶
func (m *MockLaunchdService) PlistPath() string
PlistPath returns the path where the plist file should be stored.
func (*MockLaunchdService) Status ¶
func (m *MockLaunchdService) Status() string
Status returns the current status of the service.
func (*MockLaunchdService) Uninstall ¶
func (m *MockLaunchdService) Uninstall() error
Uninstall unloads the service and removes the plist file.
type MockTUIService ¶
type MockTUIService struct {
// ConfigResult is the config to return from LoadConfig
ConfigResult *config.Config
// ConfigError is the error to return from LoadConfig
ConfigError error
// Projects is the list of projects to return
Projects []ports.TUIProjectInfo
// ProjectsError is the error to return from ListProjects
ProjectsError error
// Versions maps project names to their versions
Versions map[string][]ports.TUIVersionInfo
// VersionsError is the error to return from ListVersions
VersionsError error
// BackupResults maps project names to backup results
BackupResults map[string]ports.TUIBackupResult
// VerifyErrors maps project names to verify errors
VerifyErrors map[string]error
// Call tracking
LoadConfigCalls int
ListProjectsCalls int
ListVersionsCalls []string
RunBackupCalls []string
VerifyBackupCalls []string
}
MockTUIService implements ports.TUIService for testing.
func NewMockTUIService ¶
func NewMockTUIService() *MockTUIService
NewMockTUIService creates a new mock TUI service.
func (*MockTUIService) ListProjects ¶
func (m *MockTUIService) ListProjects(cfg *config.Config) ([]ports.TUIProjectInfo, error)
ListProjects returns all projects with their metadata.
func (*MockTUIService) ListVersions ¶
func (m *MockTUIService) ListVersions(cfg *config.Config, project string) ([]ports.TUIVersionInfo, error)
ListVersions returns all backup versions for a project.
func (*MockTUIService) LoadConfig ¶
func (m *MockTUIService) LoadConfig() (*config.Config, error)
LoadConfig loads the application configuration.
func (*MockTUIService) RunBackup ¶
func (m *MockTUIService) RunBackup(cfg *config.Config, project string) ports.TUIBackupResult
RunBackup performs a backup of the specified project.
func (*MockTUIService) VerifyBackup ¶
func (m *MockTUIService) VerifyBackup(cfg *config.Config, project string) error
VerifyBackup verifies the latest backup of a project.