testutil

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package testutil provides test helpers for git repository testing.

Index

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) CommitAll

func (r *GitTestRepo) CommitAll(msg string)

CommitAll stages and commits all changes.

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) 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) 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL