testutils

package
v0.0.0-...-439ed03 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestData = struct {
	// MinimalPNGTransparent is a 1x1 transparent PNG image
	MinimalPNGTransparent []byte
	// MinimalPNGRed is a 1x1 red PNG image
	MinimalPNGRed []byte
}{
	MinimalPNGTransparent: []byte{
		0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A,
		0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
		0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
		0x08, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4,
		0x89, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x44, 0x41,
		0x54, 0x78, 0x9C, 0x62, 0x00, 0x00, 0x00, 0x02,
		0x00, 0x01, 0xE5, 0x27, 0xDE, 0xFC, 0x00, 0x00,
		0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42,
		0x60, 0x82,
	},
	MinimalPNGRed: []byte{
		0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A,
		0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
		0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
		0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53,
		0xDE, 0x00, 0x00, 0x00, 0x0C, 0x49, 0x44, 0x41,
		0x54, 0x08, 0x99, 0x63, 0xF8, 0xCF, 0xC0, 0x00,
		0x00, 0x03, 0x01, 0x01, 0x00, 0x18, 0xDD, 0x8D,
		0xB4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E,
		0x44, 0xAE, 0x42, 0x60, 0x82,
	},
}

TestData contains common test data like binary files

Functions

func AssertDiffContains

func AssertDiffContains(t *testing.T, diff string, want ...string)

AssertDiffContains verifies that the given diff contains all expected strings. It calls t.Helper() to ensure accurate stack traces and fails the test if any expected string is missing.

func AssertDiffNotContains

func AssertDiffNotContains(t *testing.T, diff string, unwanted ...string)

AssertDiffNotContains verifies that the given diff does not contain any unwanted strings. It calls t.Helper() to ensure accurate stack traces and fails the test if any unwanted string is found.

func CreateAndCommitFile

func CreateAndCommitFile(t *testing.T, dir string, repo *git.Repository, filename, content, message string)

CreateAndCommitFile creates a file with the given content and commits it (legacy function for backward compatibility)

func CreateLargeFileWithManyHunks

func CreateLargeFileWithManyHunks(t *testing.T, tmpDir string, repo *git.Repository)

CreateLargeFileWithManyHunks creates a file with many functions for performance testing (legacy function for backward compatibility)

func CreateTestRepo

func CreateTestRepo(t *testing.T, prefix string) (string, *git.Repository, func())

CreateTestRepo creates a temporary directory with an initialized git repository (legacy function for backward compatibility)

func GenerateFunction

func GenerateFunction(index int, version string) string

GenerateFunction generates a function with the given index and version

func RunCommand

func RunCommand(t *testing.T, dir string, command string, args ...string) (string, error)

RunCommand executes a command in the specified directory (legacy function for backward compatibility)

func SetupTestDir

func SetupTestDir(t *testing.T, dir string) func()

SetupTestDir changes to the test directory and returns a cleanup function (legacy function for backward compatibility)

Types

type TestRepo

type TestRepo struct {
	Path string
	Repo *git.Repository
	// contains filtered or unexported fields
}

TestRepo provides a unified interface for test repositories

func NewTestRepo

func NewTestRepo(t *testing.T, prefix string) *TestRepo

NewTestRepo creates a new test repository with proper initialization

func (*TestRepo) Chdir

func (tr *TestRepo) Chdir() func()

Chdir changes to the repository directory and returns a cleanup function

func (*TestRepo) Cleanup

func (tr *TestRepo) Cleanup()

Cleanup removes the test repository

func (*TestRepo) CommitAllChanges

func (tr *TestRepo) CommitAllChanges(message string) error

CommitAllChanges commits all changes with the given message

func (*TestRepo) CommitChanges

func (tr *TestRepo) CommitChanges(message string)

CommitChanges commits all changes with the given message

func (*TestRepo) CreateAndCommitFile

func (tr *TestRepo) CreateAndCommitFile(filename, content, message string)

CreateAndCommitFile creates a file and commits it in one operation

func (*TestRepo) CreateBinaryFile

func (tr *TestRepo) CreateBinaryFile(filename string, content []byte)

CreateBinaryFile creates a binary file with the given content

func (*TestRepo) CreateFile

func (tr *TestRepo) CreateFile(filename, content string)

CreateFile creates a file in the repository, creating directories as needed

func (*TestRepo) CreateFileWithContent

func (tr *TestRepo) CreateFileWithContent(filename, content string) error

CreateFileWithContent creates a file with content, creating directories as needed

func (*TestRepo) CreateLargeFileWithManyHunks

func (tr *TestRepo) CreateLargeFileWithManyHunks()

CreateLargeFileWithManyHunks creates a file with many functions for performance testing

func (*TestRepo) CreatePatchFile

func (tr *TestRepo) CreatePatchFile(filename, ref string) error

CreatePatchFile creates a patch file from the current diff against the given ref

func (*TestRepo) GeneratePatch

func (tr *TestRepo) GeneratePatch(filename string)

GeneratePatch generates a patch file for all changes since HEAD. This includes both staged (intent-to-add) and unstaged changes, matching the recommended workflow in CLAUDE.md for LLM agent integration.

func (*TestRepo) GetCommitCount

func (tr *TestRepo) GetCommitCount() int

GetCommitCount returns the number of commits in the repository

func (*TestRepo) GetFilePath

func (tr *TestRepo) GetFilePath(filename string) string

GetFilePath returns the full path to a file in the repository

func (*TestRepo) GetStagedFiles

func (tr *TestRepo) GetStagedFiles() []string

GetStagedFiles returns a list of staged files

func (*TestRepo) GetTempFilePath

func (tr *TestRepo) GetTempFilePath(filename string) string

GetTempFilePath returns a path for a temporary file in the repo

func (*TestRepo) ModifyFile

func (tr *TestRepo) ModifyFile(filename, newContent string)

ModifyFile modifies an existing file with new content

func (*TestRepo) RunCommand

func (tr *TestRepo) RunCommand(command string, args ...string) (string, error)

RunCommand executes a command in the repository directory

func (*TestRepo) RunCommandOrFail

func (tr *TestRepo) RunCommandOrFail(command string, args ...string) string

RunCommandOrFail executes a command and fails the test if it errors

func (*TestRepo) WriteBinaryFile

func (tr *TestRepo) WriteBinaryFile(filename string, content []byte) error

WriteBinaryFile creates a binary file with content, creating directories as needed

func (*TestRepo) WriteFile

func (tr *TestRepo) WriteFile(filename, content string) error

WriteFile writes content to a file, creating directories as needed

Jump to

Keyboard shortcuts

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