Documentation
¶
Overview ¶
Package testutil provides common utilities and helpers for testing dodot. It includes custom assertions, test fixture generators, and mock implementations to streamline the development of tests.
Index ¶
- func AssertContains(t *testing.T, str, substr string, msgAndArgs ...interface{})
- func AssertDirExists(t *testing.T, path string, msgAndArgs ...interface{})
- func AssertEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{})
- func AssertError(t *testing.T, err error, msgAndArgs ...interface{})
- func AssertErrorContains(t *testing.T, err error, substr string, msgAndArgs ...interface{})
- func AssertFalse(t *testing.T, value bool, msgAndArgs ...interface{})
- func AssertFileContent(t *testing.T, path, expected string)
- func AssertFileExists(t *testing.T, path string, msgAndArgs ...interface{})
- func AssertMapEqual(t *testing.T, expected, actual map[string]string, msgAndArgs ...interface{})
- func AssertNil(t *testing.T, value interface{}, msgAndArgs ...interface{})
- func AssertNoError(t *testing.T, err error, msgAndArgs ...interface{})
- func AssertNoFile(t *testing.T, path string)
- func AssertNoPanic(t *testing.T, fn func(), msgAndArgs ...interface{})
- func AssertNotContains(t *testing.T, str, substr string, msgAndArgs ...interface{})
- func AssertNotEmpty(t *testing.T, value string, msgAndArgs ...interface{})
- func AssertNotEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{})
- func AssertNotNil(t *testing.T, value interface{}, msgAndArgs ...interface{})
- func AssertPanic(t *testing.T, fn func(), msgAndArgs ...interface{})
- func AssertSliceEqual(t *testing.T, expected, actual []string, msgAndArgs ...interface{})
- func AssertSymlink(t *testing.T, link, expectedTarget string)
- func AssertTrue(t *testing.T, value bool, msgAndArgs ...interface{})
- func CalculateFileChecksum(filepath string) (string, error)
- func Chmod(t *testing.T, path string, mode os.FileMode)
- func CommandAvailable(name string) bool
- func CreateComplexPack(t *testing.T, baseDir string) string
- func CreateDir(t *testing.T, parent, name string) string
- func CreateDotfilesRepo(t *testing.T) string
- func CreateFile(t *testing.T, dir, name, content string) string
- func CreateMinimalPack(t *testing.T, baseDir, packName string) string
- func CreatePackFixture(t *testing.T, baseDir string, fixture PackFixture) string
- func CreateSymlink(t *testing.T, target, link string)
- func DirExists(t *testing.T, path string) bool
- func FileExists(t *testing.T, path string) bool
- func ReadFile(t *testing.T, path string) string
- func ReadSymlink(t *testing.T, path string) string
- func RequireRoot(t *testing.T)
- func RunCommand(t *testing.T, name string, args ...string)
- func Setenv(t *testing.T, key, value string)
- func SkipOnWindows(t *testing.T)
- func SymlinkExists(t *testing.T, path string) bool
- func TempDir(t *testing.T, prefix string) string
- type MockPowerUp
- func (m *MockPowerUp) Description() string
- func (m *MockPowerUp) GetTemplateContent() string
- func (m *MockPowerUp) Name() string
- func (m *MockPowerUp) Process(matches []types.TriggerMatch) ([]types.Action, error)
- func (m *MockPowerUp) RunMode() types.RunMode
- func (m *MockPowerUp) ValidateOptions(options map[string]interface{}) error
- type MockTrigger
- type PackFixture
- type TB
- type TestEnvironment
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertContains ¶
AssertContains checks if a string contains a substring
func AssertDirExists ¶
AssertDirExists checks that a directory exists.
func AssertEqual ¶
AssertEqual checks if two values are equal using deep equality
func AssertError ¶
AssertError checks if an error occurred
func AssertErrorContains ¶
AssertErrorContains checks if an error occurred and contains a specific substring
func AssertFalse ¶
AssertFalse checks if a value is false
func AssertFileContent ¶
AssertFileContent checks that a file exists and has the expected content.
func AssertFileExists ¶
AssertFileExists checks that a file exists.
func AssertMapEqual ¶
AssertMapEqual checks if two string maps are equal
func AssertNoError ¶
AssertNoError checks if no error occurred
func AssertNoFile ¶
AssertNoFile checks that a file does not exist.
func AssertNoPanic ¶
AssertNoPanic checks if a function does not panic
func AssertNotContains ¶
AssertNotContains checks if a string does not contain a substring
func AssertNotEmpty ¶
AssertNotEmpty checks that a string is not empty
func AssertNotEqual ¶
AssertNotEqual checks if two values are not equal
func AssertNotNil ¶
AssertNotNil checks if a value is not nil
func AssertPanic ¶
AssertPanic checks if a function panics
func AssertSliceEqual ¶
AssertSliceEqual checks if two slices are equal (ignoring order)
func AssertSymlink ¶
AssertSymlink checks that a symlink exists and points to the expected target.
func AssertTrue ¶
AssertTrue checks if a value is true
func CalculateFileChecksum ¶
CalculateFileChecksum calculates SHA256 checksum of a file
func Chmod ¶
Chmod changes the permissions of a file or directory. It fails the test if the operation fails.
func CommandAvailable ¶ added in v0.1.0
CommandAvailable checks if a command is available in the system PATH
func CreateComplexPack ¶
CreateComplexPack creates a pack with various file types for comprehensive testing
func CreateDir ¶
CreateDir creates a directory in the specified parent directory. It fails the test if the directory cannot be created.
func CreateDotfilesRepo ¶
CreateDotfilesRepo creates a complete test dotfiles repository
func CreateFile ¶
CreateFile creates a file with the given content in the specified directory. It fails the test if the file cannot be created.
func CreateMinimalPack ¶
CreateMinimalPack creates a minimal pack for simple tests
func CreatePackFixture ¶
func CreatePackFixture(t *testing.T, baseDir string, fixture PackFixture) string
CreatePackFixture creates a pack fixture in the given directory
func CreateSymlink ¶
CreateSymlink creates a symbolic link pointing to target. It fails the test if the symlink cannot be created.
func FileExists ¶
FileExists checks if a file exists and is not a directory.
func ReadFile ¶
ReadFile reads the content of a file and returns it as a string. It fails the test if the file cannot be read.
func ReadSymlink ¶
ReadSymlink reads the target of a symbolic link. It fails the test if the link cannot be read.
func RequireRoot ¶
RequireRoot skips the test if not running as root.
func RunCommand ¶ added in v0.1.0
RunCommand runs a command and fails the test if it returns an error
func SkipOnWindows ¶
SkipOnWindows skips the test if running on Windows.
func SymlinkExists ¶
SymlinkExists checks if a path is a symbolic link.
Types ¶
type MockPowerUp ¶
type MockPowerUp struct {
NameFunc func() string
DescriptionFunc func() string
RunModeFunc func() types.RunMode
ProcessFunc func(matches []types.TriggerMatch) ([]types.Action, error)
ValidateOptionsFunc func(options map[string]interface{}) error
GetTemplateContentFunc func() string
}
MockPowerUp is a mock implementation of the types.PowerUp interface for testing.
func (*MockPowerUp) Description ¶
func (m *MockPowerUp) Description() string
Description returns the mock's description.
func (*MockPowerUp) GetTemplateContent ¶ added in v0.1.1
func (m *MockPowerUp) GetTemplateContent() string
GetTemplateContent returns the mock's template content.
func (*MockPowerUp) Process ¶
func (m *MockPowerUp) Process(matches []types.TriggerMatch) ([]types.Action, error)
Process runs the mock's process function.
func (*MockPowerUp) RunMode ¶
func (m *MockPowerUp) RunMode() types.RunMode
RunMode returns the mock's run mode.
func (*MockPowerUp) ValidateOptions ¶
func (m *MockPowerUp) ValidateOptions(options map[string]interface{}) error
ValidateOptions runs the mock's validate options function.
type MockTrigger ¶
type MockTrigger struct {
NameFunc func() string
DescriptionFunc func() string
PriorityFunc func() int
MatchFunc func(path string, info fs.FileInfo) (bool, map[string]interface{})
TypeFunc func() types.TriggerType
}
MockTrigger is a mock implementation of the types.Trigger interface for testing.
func (*MockTrigger) Description ¶
func (m *MockTrigger) Description() string
Description returns the mock's description.
func (*MockTrigger) Priority ¶
func (m *MockTrigger) Priority() int
Priority returns the mock's priority.
func (*MockTrigger) Type ¶ added in v0.1.1
func (m *MockTrigger) Type() types.TriggerType
Type returns the mock's trigger type.
type PackFixture ¶
PackFixture represents a test pack with files and directories
func CommonPackFixtures ¶
func CommonPackFixtures() []PackFixture
CommonPackFixtures returns common pack fixtures for testing
type TB ¶
type TB interface {
Helper()
Error(args ...interface{})
Errorf(format string, args ...interface{})
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
Skip(args ...interface{})
Skipf(format string, args ...interface{})
Log(args ...interface{})
Logf(format string, args ...interface{})
TempDir() string
}
TB is a subset of testing.TB interface that we use for our test helpers This allows us to use both *testing.T and mock implementations
type TestEnvironment ¶ added in v0.1.1
type TestEnvironment struct {
// contains filtered or unexported fields
}
TestEnvironment provides isolated directories for integration testing
func NewTestEnvironment ¶ added in v0.1.1
func NewTestEnvironment(t *testing.T, name string) *TestEnvironment
NewTestEnvironment creates a new test environment with isolated directories
func (*TestEnvironment) Cleanup ¶ added in v0.1.1
func (te *TestEnvironment) Cleanup()
Cleanup is a no-op as t.TempDir() handles cleanup automatically
func (*TestEnvironment) CreatePack ¶ added in v0.1.1
func (te *TestEnvironment) CreatePack(name string) string
CreatePack creates a new pack directory and returns its path
func (*TestEnvironment) DataDir ¶ added in v0.1.1
func (te *TestEnvironment) DataDir() string
DataDir returns the dodot data directory
func (*TestEnvironment) DotfilesRoot ¶ added in v0.1.1
func (te *TestEnvironment) DotfilesRoot() string
DotfilesRoot returns the dotfiles root directory
func (*TestEnvironment) Home ¶ added in v0.1.1
func (te *TestEnvironment) Home() string
Home returns the test home directory