Documentation
¶
Overview ¶
Package testutil provides utilities for testing.
Index ¶
- func AddRemote(t *testing.T, repoDir, name, url string)
- func BackgroundContext() context.Context
- func CancelableContext(t *testing.T) (context.Context, context.CancelFunc)
- func CommitFile(t *testing.T, repoDir, path, content, message string)
- func CopyFixture(t *testing.T, fixturePath string) string
- func CreateBranch(t *testing.T, repoDir, branch string)
- func GetCurrentBranch(t *testing.T, repoDir string) string
- func GetHeadSHA(t *testing.T, repoDir string) string
- func GetShortSHA(t *testing.T, repoDir string) string
- func LoadFixture(t *testing.T, path string) []byte
- func LoadFixtureString(t *testing.T, path string) string
- func LoadJSONFixture[T any](t *testing.T, path string) T
- func MergeBranch(t *testing.T, repoDir, branch string)
- func MustLoadFixture(path string) []byte
- func SetupTestRepo(t *testing.T) string
- func SetupTestRepoWithFiles(t *testing.T, files map[string]string) string
- func Stash(t *testing.T, repoDir string)
- func StashPop(t *testing.T, repoDir string)
- func SwitchBranch(t *testing.T, repoDir, branch string)
- func TODO() context.Context
- func Tag(t *testing.T, repoDir, tag string)
- func TempDir(t *testing.T) string
- func TempFile(t *testing.T, name string, content []byte) string
- func TempFileString(t *testing.T, name, content string) string
- func TestContext(t *testing.T) context.Context
- func TestContextWithDeadline(t *testing.T, deadline time.Time) context.Context
- func TestContextWithTimeout(t *testing.T, timeout time.Duration) context.Context
- func TestNameFromContext(ctx context.Context) string
- func WithTestName(ctx context.Context, t *testing.T) context.Context
- func WithValue(ctx context.Context, key, value any) context.Context
- func WriteFixture(t *testing.T, path string, data []byte)
- func WriteJSONFixture(t *testing.T, path string, v any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BackgroundContext ¶
BackgroundContext returns context.Background() for use in tests where cleanup isn't needed.
func CancelableContext ¶
CancelableContext returns a context and cancel function. The context is automatically canceled when the test ends if not canceled earlier.
func CommitFile ¶
CommitFile creates or updates a file and commits it.
func CopyFixture ¶
CopyFixture copies a fixture file to a temporary location. Returns the path to the copy.
func CreateBranch ¶
CreateBranch creates a new branch in the test repo.
func GetCurrentBranch ¶
GetCurrentBranch returns the current branch name.
func GetHeadSHA ¶
GetHeadSHA returns the current HEAD SHA.
func GetShortSHA ¶
GetShortSHA returns the short SHA for HEAD.
func LoadFixture ¶
LoadFixture loads a fixture file from the testdata directory. The path is relative to the testdata directory.
func LoadFixtureString ¶
LoadFixtureString loads a fixture file as a string.
func LoadJSONFixture ¶
LoadJSONFixture loads a fixture file and unmarshals it as JSON.
func MergeBranch ¶
MergeBranch merges a branch into the current branch.
func MustLoadFixture ¶
MustLoadFixture loads a fixture file, panicking on error. Use this for test setup outside of test functions.
func SetupTestRepo ¶
SetupTestRepo creates a temporary git repository for testing. Returns the path to the repository. The repository is automatically cleaned up when the test ends.
func SetupTestRepoWithFiles ¶
SetupTestRepoWithFiles creates a test repo with specified files.
func SwitchBranch ¶
SwitchBranch switches to an existing branch.
func TempDir ¶
TempDir creates a temporary directory for the test. It returns the directory path and is automatically cleaned up when the test ends.
func TempFile ¶
TempFile creates a temporary file with the given content. Returns the file path. File is automatically cleaned up when the test ends.
func TempFileString ¶
TempFileString creates a temporary file with string content.
func TestContext ¶
TestContext returns a context that is canceled when the test ends. This ensures any goroutines started during the test are properly cleaned up.
func TestContextWithDeadline ¶
TestContextWithDeadline returns a context with a deadline. The context is also canceled when the test ends.
func TestContextWithTimeout ¶
TestContextWithTimeout returns a context with a timeout. The context is also canceled when the test ends.
func TestNameFromContext ¶
TestNameFromContext retrieves the test name from context.
func WithTestName ¶
WithTestName adds the test name to the context.
func WithValue ¶
WithValue returns a context with the given key-value pair. This is a convenience wrapper around context.WithValue.
func WriteFixture ¶
WriteFixture writes data to a fixture file. Useful for generating test fixtures from real API responses.
Types ¶
This section is empty.