Documentation
¶
Overview ¶
Package harness provides utilities for integration testing the rocha CLI. It handles binary compilation, environment isolation, and command execution.
Environment variables managed:
- ROCHA_HOME: Isolated per test (temp directory)
- ROCHA_DEBUG: Disabled to reduce noise
- ROCHA_EDITOR: Set to prevent interactive prompts
Index ¶
- func AssertExitCode(tb testing.TB, result CommandResult, expected int)
- func AssertFailure(tb testing.TB, result CommandResult)
- func AssertJSONContains(tb testing.TB, result CommandResult, key string, expected any)
- func AssertStderrContains(tb testing.TB, result CommandResult, expected string)
- func AssertStderrEmpty(tb testing.TB, result CommandResult)
- func AssertStdoutContains(tb testing.TB, result CommandResult, expected string)
- func AssertStdoutEmpty(tb testing.TB, result CommandResult)
- func AssertStdoutNotContains(tb testing.TB, result CommandResult, unexpected string)
- func AssertSuccess(tb testing.TB, result CommandResult)
- func AssertValidJSON(tb testing.TB, result CommandResult, target any)
- func BuildBinary() (string, error)
- func CleanupBinary()
- func GetBinaryPath() string
- func RunGitCommand(tb testing.TB, dir string, args ...string)
- func TodayTimestamp() string
- type CommandResult
- type TestEnvironment
- type TestGitSetup
- func (g *TestGitSetup) CreateBranch(name string)
- func (g *TestGitSetup) CreateRemoteBranch(name string)
- func (g *TestGitSetup) CreateWorktree(path, branch string) string
- func (g *TestGitSetup) GetBareRepoPath() string
- func (g *TestGitSetup) GetClonePath() string
- func (g *TestGitSetup) PushBranch(name string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertExitCode ¶
func AssertExitCode(tb testing.TB, result CommandResult, expected int)
AssertExitCode verifies the command exited with a specific code.
func AssertFailure ¶
func AssertFailure(tb testing.TB, result CommandResult)
AssertFailure verifies the command failed with non-zero exit code.
func AssertJSONContains ¶
func AssertJSONContains(tb testing.TB, result CommandResult, key string, expected any)
AssertJSONContains verifies stdout is valid JSON and contains the expected key-value.
func AssertStderrContains ¶
func AssertStderrContains(tb testing.TB, result CommandResult, expected string)
AssertStderrContains verifies stderr contains the expected string.
func AssertStderrEmpty ¶
func AssertStderrEmpty(tb testing.TB, result CommandResult)
AssertStderrEmpty verifies stderr is empty.
func AssertStdoutContains ¶
func AssertStdoutContains(tb testing.TB, result CommandResult, expected string)
AssertStdoutContains verifies stdout contains the expected string.
func AssertStdoutEmpty ¶
func AssertStdoutEmpty(tb testing.TB, result CommandResult)
AssertStdoutEmpty verifies stdout is empty.
func AssertStdoutNotContains ¶
func AssertStdoutNotContains(tb testing.TB, result CommandResult, unexpected string)
AssertStdoutNotContains verifies stdout does not contain the string.
func AssertSuccess ¶
func AssertSuccess(tb testing.TB, result CommandResult)
AssertSuccess verifies the command succeeded with exit code 0.
func AssertValidJSON ¶
func AssertValidJSON(tb testing.TB, result CommandResult, target any)
AssertValidJSON verifies stdout is valid JSON and unmarshals it into target.
func BuildBinary ¶
BuildBinary compiles the rocha binary once per test run. Call this from TestMain before running tests.
func CleanupBinary ¶
func CleanupBinary()
CleanupBinary removes the compiled binary and its temp directory. Call this from TestMain after tests complete.
func GetBinaryPath ¶
func GetBinaryPath() string
GetBinaryPath returns the path to the compiled binary.
func RunGitCommand ¶
RunGitCommand executes a git command in the specified directory (exported for tests).
func TodayTimestamp ¶
func TodayTimestamp() string
TodayTimestamp returns a timestamp string for today in RFC3339 format. This is useful for creating test JSONL files with "today's" data.
Types ¶
type CommandResult ¶
CommandResult holds the result of running a CLI command
func RunCommand ¶
func RunCommand(tb testing.TB, env *TestEnvironment, args ...string) CommandResult
RunCommand executes the rocha binary with given arguments using default timeout.
func RunCommandWithEnv ¶
func RunCommandWithEnv(tb testing.TB, environ []string, args ...string) CommandResult
RunCommandWithEnv executes the rocha binary with a custom environment. This is useful for tests that need to override HOME or other environment variables.
func RunCommandWithTimeout ¶
func RunCommandWithTimeout(tb testing.TB, env *TestEnvironment, timeout time.Duration, args ...string) CommandResult
RunCommandWithTimeout executes the rocha binary with given arguments and timeout.
type TestEnvironment ¶
type TestEnvironment struct {
RochaHome string
// contains filtered or unexported fields
}
TestEnvironment provides an isolated test environment with its own ROCHA_HOME.
func NewTestEnvironment ¶
func NewTestEnvironment(tb testing.TB) *TestEnvironment
NewTestEnvironment creates an isolated test environment with a temp ROCHA_HOME. The temp directory is automatically cleaned up when the test completes.
func (*TestEnvironment) DBPath ¶
func (e *TestEnvironment) DBPath() string
DBPath returns the path to the test database.
func (*TestEnvironment) Environ ¶
func (e *TestEnvironment) Environ() []string
Environ returns environment variables configured for test isolation. It filters out ROCHA_* variables and sets:
- ROCHA_HOME to the temp directory
- ROCHA_DEBUG to empty string (disables debug logging)
- ROCHA_EDITOR to "true" (no-op command)
func (*TestEnvironment) SetEnv ¶
func (e *TestEnvironment) SetEnv(key, value string)
SetEnv sets an additional environment variable for this test environment.
func (*TestEnvironment) TempDir ¶
func (e *TestEnvironment) TempDir() string
TempDir returns the root temp directory used for this test environment.
func (*TestEnvironment) WorktreesPath ¶
func (e *TestEnvironment) WorktreesPath() string
WorktreesPath returns the path to the worktrees directory.
type TestGitSetup ¶
type TestGitSetup struct {
BareRepoPath string // Acts as "origin" remote
ClonePath string // Working repo with origin configured
// contains filtered or unexported fields
}
TestGitSetup holds paths for a complete git test environment. It creates a bare repo (simulating remote/origin) and a clone with origin configured.
func NewTestGitSetup ¶
func NewTestGitSetup(tb testing.TB) *TestGitSetup
NewTestGitSetup creates a complete git environment with origin.
- Creates a bare repo (simulates remote/origin)
- Clones it to create a working repo with origin remote
- Creates initial commit so branches work
Setup structure:
tb.TempDir()/
├── bare/ <- git init --bare (acts as origin)
└── clone/ <- git clone bare/ clone/ (has origin remote)
└── worktrees/ <- git worktree add ...
func (*TestGitSetup) CreateBranch ¶
func (g *TestGitSetup) CreateBranch(name string)
CreateBranch creates a branch in the working repo.
func (*TestGitSetup) CreateRemoteBranch ¶
func (g *TestGitSetup) CreateRemoteBranch(name string)
CreateRemoteBranch creates a branch that exists only on origin. It creates a local branch, pushes it to origin, then deletes the local branch.
func (*TestGitSetup) CreateWorktree ¶
func (g *TestGitSetup) CreateWorktree(path, branch string) string
CreateWorktree creates a git worktree at the given path for the specified branch. Returns the full path to the created worktree.
func (*TestGitSetup) GetBareRepoPath ¶
func (g *TestGitSetup) GetBareRepoPath() string
GetBareRepoPath returns the path to the bare repository (origin).
func (*TestGitSetup) GetClonePath ¶
func (g *TestGitSetup) GetClonePath() string
GetClonePath returns the path to the clone directory.
func (*TestGitSetup) PushBranch ¶
func (g *TestGitSetup) PushBranch(name string)
PushBranch pushes a branch to origin (bare repo).