Documentation
¶
Overview ¶
Package testutil provides common test utilities and helpers for FoGit tests.
Index ¶
- func AssertContains(t *testing.T, got, substr string, msg string)
- func AssertEqual[T comparable](t *testing.T, got, want T, msg string)
- func AssertError(t *testing.T, err error, expected error)
- func AssertFalse(t *testing.T, condition bool, msg string)
- func AssertNil(t *testing.T, val interface{}, msg string)
- func AssertNoError(t *testing.T, err error)
- func AssertNotContains(t *testing.T, got, substr string, msg string)
- func AssertNotNil(t *testing.T, val interface{}, msg string)
- func AssertTrue(t *testing.T, condition bool, msg string)
- func InDir(t *testing.T, dir string, fn func())
- func NewTestFeature(name string) *fogit.Feature
- func NewTestFeatureWithPriority(name string, priority fogit.Priority) *fogit.Feature
- func NewTestFeatureWithType(name, featureType string) *fogit.Feature
- func RequireNoError(t *testing.T, err error, msg string)
- func SetupTestRepository(t *testing.T) (*storage.FileRepository, func())
- func TempDir(t *testing.T) (string, func())
- func TempDirWithFogit(t *testing.T) (rootDir string, fogitDir string, cleanup func())
- func WithDescription(desc string) func(*fogit.Feature)
- func WithPriority(p fogit.Priority) func(*fogit.Feature)
- func WithType(featureType string) func(*fogit.Feature)
- type GitTestEnv
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertContains ¶
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 ¶
AssertError checks that an error occurred and optionally matches the expected error.
func AssertFalse ¶
AssertFalse checks that a condition is false.
func AssertNoError ¶
AssertNoError checks that no error occurred.
func AssertNotContains ¶
AssertNotContains checks that a string does not contain a substring.
func AssertNotNil ¶
AssertNotNil checks that a value is not nil.
func AssertTrue ¶
AssertTrue checks that a condition is true.
func InDir ¶ added in v1.0.2
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 ¶
NewTestFeature creates a new feature with the given name for testing. It sets common defaults that are useful for tests.
func NewTestFeatureWithPriority ¶
NewTestFeatureWithPriority creates a new feature with the given name and priority for testing.
func NewTestFeatureWithType ¶
NewTestFeatureWithType creates a new feature with the given name and type for testing.
func RequireNoError ¶
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 ¶
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 ¶
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 ¶
WithDescription returns an option function to set feature description.
func WithPriority ¶
WithPriority returns an option function to set feature priority.
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 ¶
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.