Documentation
¶
Overview ¶
Package testutil provides test helpers for git repository testing.
Index ¶
- type ComparisonTest
- type GitTestRepo
- func (r *GitTestRepo) CheckoutBranch(name string)
- func (r *GitTestRepo) CommitAll(msg string)
- func (r *GitTestRepo) CreateBranch(name string)
- func (r *GitTestRepo) Diff() string
- func (r *GitTestRepo) DiffCached() string
- func (r *GitTestRepo) FileExists(path string) bool
- func (r *GitTestRepo) GetCommitCount() int
- func (r *GitTestRepo) GetCommitMessage() string
- func (r *GitTestRepo) GetFullHash() string
- func (r *GitTestRepo) GetShortHash() string
- func (r *GitTestRepo) Git(args ...string) string
- func (r *GitTestRepo) GitMayFail(args ...string) (string, error)
- func (r *GitTestRepo) LogOneline() string
- func (r *GitTestRepo) ReadFile(path string) string
- func (r *GitTestRepo) StageFile(path string)
- func (r *GitTestRepo) WriteFile(path, content string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ComparisonTest ¶
type ComparisonTest struct {
Expected *GitTestRepo
Actual *GitTestRepo
// contains filtered or unexported fields
}
ComparisonTest represents a comparison between two git operations. Used to verify hunk produces identical results to manual git operations.
func NewComparisonTest ¶
func NewComparisonTest( t *testing.T, setup func(r *GitTestRepo), ) *ComparisonTest
NewComparisonTest creates two identical repos for comparison testing. The setup function is called on both repos to establish identical state.
func (*ComparisonTest) AssertSameContent ¶
func (c *ComparisonTest) AssertSameContent(paths ...string)
AssertSameContent verifies both repos have identical file contents.
func (*ComparisonTest) AssertSameDiff ¶
func (c *ComparisonTest) AssertSameDiff()
AssertSameDiff verifies both repos have identical staged diffs.
func (*ComparisonTest) AssertSameUnstagedDiff ¶
func (c *ComparisonTest) AssertSameUnstagedDiff()
AssertSameUnstagedDiff verifies both repos have identical unstaged diffs.
type GitTestRepo ¶
type GitTestRepo struct {
Dir string
// contains filtered or unexported fields
}
GitTestRepo creates a temporary git repository for testing.
func NewGitTestRepo ¶
func NewGitTestRepo(t *testing.T) *GitTestRepo
NewGitTestRepo creates a new test repo with git initialized.
func (*GitTestRepo) CheckoutBranch ¶ added in v1.0.1
func (r *GitTestRepo) CheckoutBranch(name string)
CheckoutBranch switches to an existing branch.
func (*GitTestRepo) CommitAll ¶
func (r *GitTestRepo) CommitAll(msg string)
CommitAll stages and commits all changes.
func (*GitTestRepo) CreateBranch ¶ added in v1.0.1
func (r *GitTestRepo) CreateBranch(name string)
CreateBranch creates and switches to a new branch.
func (*GitTestRepo) Diff ¶
func (r *GitTestRepo) Diff() string
Diff returns the current unstaged diff.
func (*GitTestRepo) DiffCached ¶
func (r *GitTestRepo) DiffCached() string
DiffCached returns the current staged diff.
func (*GitTestRepo) FileExists ¶
func (r *GitTestRepo) FileExists(path string) bool
FileExists checks if a file exists in the repo.
func (*GitTestRepo) GetCommitCount ¶ added in v1.0.1
func (r *GitTestRepo) GetCommitCount() int
GetCommitCount returns the number of commits in the repository.
func (*GitTestRepo) GetCommitMessage ¶ added in v1.0.1
func (r *GitTestRepo) GetCommitMessage() string
GetCommitMessage returns the full commit message of HEAD.
func (*GitTestRepo) GetFullHash ¶ added in v1.0.1
func (r *GitTestRepo) GetFullHash() string
GetFullHash returns the full hash of HEAD.
func (*GitTestRepo) GetShortHash ¶ added in v1.0.1
func (r *GitTestRepo) GetShortHash() string
GetShortHash returns the short hash of HEAD.
func (*GitTestRepo) Git ¶
func (r *GitTestRepo) Git(args ...string) string
Git runs a git command in the test repo.
func (*GitTestRepo) GitMayFail ¶
func (r *GitTestRepo) GitMayFail(args ...string) (string, error)
GitMayFail runs a git command that may fail, returning the error.
func (*GitTestRepo) LogOneline ¶ added in v1.0.1
func (r *GitTestRepo) LogOneline() string
LogOneline returns git log --oneline output.
func (*GitTestRepo) ReadFile ¶
func (r *GitTestRepo) ReadFile(path string) string
ReadFile reads a file from the repo.
func (*GitTestRepo) StageFile ¶
func (r *GitTestRepo) StageFile(path string)
StageFile stages a specific file.
func (*GitTestRepo) WriteFile ¶
func (r *GitTestRepo) WriteFile(path, content string)
WriteFile creates or overwrites a file in the repo.