harness

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Harness

type Harness struct {
	// contains filtered or unexported fields
}

Harness provides an isolated filesystem environment for integration tests. It creates temp directories, sets XDG env vars, registers a project, and optionally persists config — all driven by what the caller wired into the Factory.

func New added in v0.3.0

func New(t *testing.T, f *cmdutil.Factory, opts ...Option) *Harness

New creates an isolated test environment and returns a Harness.

The caller passes a pre-built *cmdutil.Factory. The harness:

  1. Creates temp dirs for config, data, state, and project
  2. Sets CLAWKER_CONFIG_DIR, CLAWKER_DATA_DIR, CLAWKER_STATE_DIR via t.Setenv
  3. If f.ProjectManager is set (and not opted out): registers "testrepo" at projectDir
  4. Chdirs to projectDir (restored on cleanup)

func (*Harness) ProjectDir

func (h *Harness) ProjectDir() string

ProjectDir returns the path to the isolated project directory.

func (*Harness) Run added in v0.3.0

func (h *Harness) Run(args ...string) *RunResult

Run executes a CLI command through the full root.NewCmdRoot Cobra pipeline using the stored factory. IO is whatever the caller wired into the factory.

func (*Harness) WriteConfig added in v0.3.0

func (h *Harness) WriteConfig(cfg config.Config)

WriteConfig persists a config.Config to disk by calling Write() on its project and settings stores. Call this after New() to persist config that was created using the harness's env vars.

type Option added in v0.3.0

type Option func(*options)

Option configures harness behavior.

func WithConfig

func WithConfig(cfg config.Config) Option

WithConfig persists a config.Config to disk via its store Write() methods. The Config must be created AFTER harness.New() sets env vars — pass it via a closure or create it inside the test after New() returns... but that's too late. Instead, create Config lazily: the factory's Config closure will resolve after env vars are set. Use WriteConfig() on the harness after New().

func WithoutProjectRegistered added in v0.3.0

func WithoutProjectRegistered() Option

WithoutProjectRegistered skips automatic project registration. Use this for testing init/project-init commands that do their own registration.

type RunResult added in v0.3.0

type RunResult struct {
	ExitCode int
	Err      error
}

RunResult holds the outcome of a CLI command execution.

Jump to

Keyboard shortcuts

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