testutil

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package testutil provides common test utilities and helpers for FoGit tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertContains

func AssertContains(t *testing.T, got, substr string, msg string)

AssertContains checks that a string contains a substring.

func AssertEqual

func AssertEqual[T comparable](t *testing.T, got, want T, msg string)

AssertEqual checks that two values are equal.

func AssertError

func AssertError(t *testing.T, err error, expected error)

AssertError checks that an error occurred and optionally matches the expected error.

func AssertFalse

func AssertFalse(t *testing.T, condition bool, msg string)

AssertFalse checks that a condition is false.

func AssertNil

func AssertNil(t *testing.T, val interface{}, msg string)

AssertNil checks that a value is nil.

func AssertNoError

func AssertNoError(t *testing.T, err error)

AssertNoError checks that no error occurred.

func AssertNotContains

func AssertNotContains(t *testing.T, got, substr string, msg string)

AssertNotContains checks that a string does not contain a substring.

func AssertNotNil

func AssertNotNil(t *testing.T, val interface{}, msg string)

AssertNotNil checks that a value is not nil.

func AssertTrue

func AssertTrue(t *testing.T, condition bool, msg string)

AssertTrue checks that a condition is true.

func InDir added in v1.0.2

func InDir(t *testing.T, dir string, fn func())

InDir runs a function in the specified directory and restores the original working directory after completion. This is safe to use in tests that need to change the working directory temporarily.

Usage:

tmpDir := t.TempDir()
testutil.InDir(t, tmpDir, func() {
    // Code runs with tmpDir as working directory
})
// Original directory is restored here

func NewTestFeature

func NewTestFeature(name string) *fogit.Feature

NewTestFeature creates a new feature with the given name for testing. It sets common defaults that are useful for tests.

func NewTestFeatureWithPriority

func NewTestFeatureWithPriority(name string, priority fogit.Priority) *fogit.Feature

NewTestFeatureWithPriority creates a new feature with the given name and priority for testing.

func NewTestFeatureWithType

func NewTestFeatureWithType(name, featureType string) *fogit.Feature

NewTestFeatureWithType creates a new feature with the given name and type for testing.

func RequireNoError

func RequireNoError(t *testing.T, err error, msg string)

RequireNoError fails the test immediately if err is not nil. Use this for setup steps where failure means the test cannot continue.

func SetupTestRepository

func SetupTestRepository(t *testing.T) (*storage.FileRepository, func())

SetupTestRepository creates a temporary FoGit repository for testing. This is a simpler version without Git, useful for storage-only tests.

Usage:

repo, cleanup := testutil.SetupTestRepository(t)
defer cleanup()

func TempDir

func TempDir(t *testing.T) (string, func())

TempDir creates a temporary directory for testing and returns a cleanup function. The cleanup function removes the directory and all its contents.

Usage:

tempDir, cleanup := testutil.TempDir(t)
defer cleanup()

func TempDirWithFogit

func TempDirWithFogit(t *testing.T) (rootDir string, fogitDir string, cleanup func())

TempDirWithFogit creates a temporary directory with a .fogit structure for testing. Returns the root directory path, the .fogit directory path, and a cleanup function.

Usage:

rootDir, fogitDir, cleanup := testutil.TempDirWithFogit(t)
defer cleanup()

func WithDescription

func WithDescription(desc string) func(*fogit.Feature)

WithDescription returns an option function to set feature description.

func WithPriority

func WithPriority(p fogit.Priority) func(*fogit.Feature)

WithPriority returns an option function to set feature priority.

func WithType

func WithType(featureType string) func(*fogit.Feature)

WithType returns an option function to set feature type.

Types

type GitTestEnv

type GitTestEnv struct {
	RootDir    string                  // Root directory of the test environment
	FogitDir   string                  // Path to .fogit directory
	GitRepo    *gogit.Repository       // go-git repository
	Repository *storage.FileRepository // FoGit storage repository
	// contains filtered or unexported fields
}

GitTestEnv represents a test environment with a Git repository and FoGit setup.

func TempDirWithGit

func TempDirWithGit(t *testing.T) *GitTestEnv

TempDirWithGit creates a temporary directory with an initialized Git repository. Returns a GitTestEnv with the repository configured for testing.

Usage:

env := testutil.TempDirWithGit(t)
defer env.Cleanup()

func (*GitTestEnv) Cleanup

func (e *GitTestEnv) Cleanup()

Cleanup removes the temporary test environment.

func (*GitTestEnv) CreateFeature

func (e *GitTestEnv) CreateFeature(t *testing.T, name string) *fogit.Feature

CreateFeature creates a feature in the test repository and returns it.

func (*GitTestEnv) CreateFeatureWithOptions

func (e *GitTestEnv) CreateFeatureWithOptions(t *testing.T, name string, opts ...func(*fogit.Feature)) *fogit.Feature

CreateFeatureWithOptions creates a feature with custom settings.

func (*GitTestEnv) CreateInitialCommit

func (e *GitTestEnv) CreateInitialCommit(t *testing.T)

CreateInitialCommit creates an initial commit in the test Git repository.

Jump to

Keyboard shortcuts

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