Documentation
¶
Overview ¶
Package framework provides helpers for end-to-end testing.
Package framework contains helpers for constructing repositories during end-to-end tests.
Index ¶
- func AssertCurrentBranch(t *testing.T, repo *TestRepo, expected string)
- func AssertEqual(t *testing.T, expected, actual any)
- func AssertError(t *testing.T, err error)
- func AssertErrorContains(t *testing.T, err error, expected string)
- func AssertFalse(t *testing.T, condition bool, message string)
- func AssertFileContains(t *testing.T, repo *TestRepo, path, content string)
- func AssertFileExists(t *testing.T, repo *TestRepo, path string)
- func AssertFileNotExists(t *testing.T, repo *TestRepo, path string)
- func AssertHelpfulError(t *testing.T, output string)
- func AssertMultipleStringsInOutput(t *testing.T, output string, expected []string)
- func AssertNoError(t *testing.T, err error)
- func AssertNotEqual(t *testing.T, notExpected, actual any)
- func AssertOutputContains(t *testing.T, output, expected string)
- func AssertTrue(t *testing.T, condition bool, message string)
- func AssertWorktreeCount(t *testing.T, repo *TestRepo, expected int)
- func AssertWorktreeCreated(t *testing.T, output, branch string)
- func AssertWorktreeExists(t *testing.T, repo *TestRepo, path string)
- func AssertWorktreeNotExists(t *testing.T, repo *TestRepo, path string)
- func WithTimeout(timeout time.Duration) func(cmd *exec.Cmd)
- type TestEnvironment
- func (e *TestEnvironment) Cleanup()
- func (e *TestEnvironment) CreateNonRepoDir(name string) *TestRepo
- func (e *TestEnvironment) CreateTestRepo(name string) *TestRepo
- func (*TestEnvironment) FileExists(path string) bool
- func (e *TestEnvironment) RunInDir(dir, command string, args ...string) string
- func (e *TestEnvironment) RunWTP(args ...string) (string, error)
- func (e *TestEnvironment) TmpDir() string
- func (e *TestEnvironment) WriteFile(path, content string)
- type TestRepo
- func (r *TestRepo) AddRemote(name, url string)
- func (r *TestRepo) CheckoutBranch(name string)
- func (r *TestRepo) CommitFile(filename, content, message string)
- func (r *TestRepo) CreateBranch(name string)
- func (r *TestRepo) CreateRemoteBranch(remote, branch string)
- func (r *TestRepo) CurrentBranch() string
- func (r *TestRepo) GetBranchCommitHash(branch string) string
- func (r *TestRepo) GetCommitHash() string
- func (r *TestRepo) GitStatus() string
- func (r *TestRepo) HasFile(path string) bool
- func (r *TestRepo) ListWorktrees() []string
- func (r *TestRepo) Path() string
- func (r *TestRepo) ReadFile(path string) string
- func (r *TestRepo) RunWTP(args ...string) (string, error)
- func (r *TestRepo) WriteConfig(content string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertCurrentBranch ¶
AssertCurrentBranch verifies the repository is on the expected branch.
func AssertEqual ¶
AssertEqual compares two values for equality.
func AssertError ¶
AssertError fails the test if an error is not present.
func AssertErrorContains ¶
AssertErrorContains ensures an error is present and includes the expected text.
func AssertFalse ¶
AssertFalse fails the test if the condition is true.
func AssertFileContains ¶
AssertFileContains checks that a file contains the expected content.
func AssertFileExists ¶
AssertFileExists checks that a file exists in the repository.
func AssertFileNotExists ¶
AssertFileNotExists checks that a file does not exist in the repository.
func AssertHelpfulError ¶
AssertHelpfulError validates that an error message contains helpful guidance markers.
func AssertMultipleStringsInOutput ¶
AssertMultipleStringsInOutput verifies that all expected substrings appear in the output.
func AssertNoError ¶
AssertNoError fails the test if an unexpected error is present.
func AssertNotEqual ¶
AssertNotEqual compares two values and fails if they are equal.
func AssertOutputContains ¶
AssertOutputContains checks that output includes the expected substring.
func AssertTrue ¶
AssertTrue fails the test if the condition is false.
func AssertWorktreeCount ¶
AssertWorktreeCount ensures the repository has the expected number of worktrees.
func AssertWorktreeCreated ¶
AssertWorktreeCreated verifies worktree creation output contains the expected branch name.
func AssertWorktreeExists ¶
AssertWorktreeExists asserts that a worktree entry contains the provided path substring.
func AssertWorktreeNotExists ¶
AssertWorktreeNotExists asserts that no worktree entry contains the provided path substring.
Types ¶
type TestEnvironment ¶
type TestEnvironment struct {
// contains filtered or unexported fields
}
TestEnvironment manages the temporary state for an end-to-end test run.
func NewTestEnvironment ¶
func NewTestEnvironment(t *testing.T) *TestEnvironment
NewTestEnvironment builds a new test environment and compiles the wtp binary when needed.
func (*TestEnvironment) Cleanup ¶
func (e *TestEnvironment) Cleanup()
Cleanup runs registered cleanup callbacks for the environment.
func (*TestEnvironment) CreateNonRepoDir ¶
func (e *TestEnvironment) CreateNonRepoDir(name string) *TestRepo
CreateNonRepoDir creates a directory that is not initialized as a git repository.
func (*TestEnvironment) CreateTestRepo ¶
func (e *TestEnvironment) CreateTestRepo(name string) *TestRepo
CreateTestRepo initializes a new git repository within the test environment.
func (*TestEnvironment) FileExists ¶
func (*TestEnvironment) FileExists(path string) bool
FileExists checks whether a file exists relative to the test environment root.
func (*TestEnvironment) RunInDir ¶
func (e *TestEnvironment) RunInDir(dir, command string, args ...string) string
RunInDir executes a command in the specified directory and returns combined output.
func (*TestEnvironment) RunWTP ¶
func (e *TestEnvironment) RunWTP(args ...string) (string, error)
RunWTP executes the wtp binary with the provided arguments.
func (*TestEnvironment) TmpDir ¶
func (e *TestEnvironment) TmpDir() string
TmpDir returns the temporary directory used by the test environment.
func (*TestEnvironment) WriteFile ¶
func (e *TestEnvironment) WriteFile(path, content string)
WriteFile writes file contents relative to the test environment root.
type TestRepo ¶
type TestRepo struct {
// contains filtered or unexported fields
}
TestRepo wraps a git repository created inside the test environment.
func (*TestRepo) CheckoutBranch ¶
CheckoutBranch switches to the specified branch.
func (*TestRepo) CommitFile ¶
CommitFile writes a file and commits it with the provided message.
func (*TestRepo) CreateBranch ¶
CreateBranch creates a new branch in the repository.
func (*TestRepo) CreateRemoteBranch ¶
CreateRemoteBranch pushes a branch to the specified remote.
func (*TestRepo) CurrentBranch ¶
CurrentBranch returns the currently checked-out branch name.
func (*TestRepo) GetBranchCommitHash ¶
GetBranchCommitHash returns the commit hash for the specified branch.
func (*TestRepo) GetCommitHash ¶
GetCommitHash returns the HEAD commit hash.
func (*TestRepo) GitStatus ¶
GitStatus returns the output of `git status --short` for the repository.
func (*TestRepo) ListWorktrees ¶
ListWorktrees returns the list of worktrees known to the repository.
func (*TestRepo) ReadFile ¶
ReadFile returns the contents of a file relative to the repository root.
func (*TestRepo) WriteConfig ¶
WriteConfig writes a .wtp.yml configuration file into the repository.