harness

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFactory added in v0.5.0

func NewFactory(t *testing.T, opts *FactoryOptions) (*cmdutil.Factory, *bytes.Buffer, *bytes.Buffer, *bytes.Buffer)

NewFactory constructs a *cmdutil.Factory with lazy singletons. All nouns share a single Config and Logger instance. Nil options fields use test fakes. Pass real constructors for integration tests.

Types

type CleanupReport added in v0.8.0

type CleanupReport struct {
	FirewallContainers int // count of purpose=firewall containers found
	CPContainers       int // count of purpose=controlplane containers found
	AgentContainers    int // count of test-labeled containers found
}

CleanupReport captures what infrastructure was running when cleanup ran. Tests can inspect this to fail if expected services were never started.

type FSOptions

type FSOptions struct {
	ProjectDir string // subdirectory name under base (default: "testproject")
}

FSOptions allows overriding the project directory name.

type FactoryOptions added in v0.5.0

type FactoryOptions struct {
	Config         func(...config.NewConfigOption) (config.Config, error)
	Client         func(context.Context, config.Config, *logger.Logger, ...docker.ClientOption) (*docker.Client, error)
	ProjectManager func(*logger.Logger, project.GitManagerFactory, string, *project.Registry) (project.ProjectManager, error)
	GitManager     func(string) (*git.GitManager, error)
	HostProxy      func(config.Config, *logger.Logger) (*hostproxy.Manager, error)
	SocketBridge   func(config.Config, *logger.Logger) socketbridge.SocketBridgeManager
	// UseRealAdminClient, when true, wires a production-identical
	// AdminClient closure — the exact `adminClientFunc` in
	// internal/cmd/factory/default.go (mutex-guarded cache +
	// cacheableState re-dial on TransientFailure/Shutdown +
	// keepalive params + adminclient.Dial). Pure dial — does NOT
	// bootstrap the CP; lifecycle is owned by container-start and
	// explicit `controlplane up`, so E2E tests fail fast when the
	// CP is down (matching CLI behavior). When false the harness
	// wires a no-op AdminServiceClientMock.
	UseRealAdminClient bool
	// ControlPlane optionally provides a real Manager that drives the
	// host-side CP container lifecycle. When nil the harness wires a
	// no-op ManagerMock (every method returns zero values / nil) so
	// tests that don't exercise the CP verbs never bootstrap a real CP.
	ControlPlane func(config.Config, *logger.Logger) cpboot.Manager
}

FactoryOptions holds dependency constructor overrides. Some nil fields use test fakes (configmocks, mocks.FakeClient, hostproxytest.MockManager, cpmocks.AdminServiceClientMock). Logger always uses logger.New (real file logger). ProjectManager, GitManager, and SocketBridge default to nil. Set a field to the real constructor (e.g. config.NewConfig) for integration tests.

type Harness

type Harness struct {
	T    *testing.T
	Opts *FactoryOptions

	// Cleanup stores the cleanup report after the test environment is torn down.
	// Firewall tests can check this to fail if the stack was never running.
	Cleanup *CleanupReport
}

Harness provides an isolated filesystem environment for integration tests. Each Run() creates a fresh Factory from Opts — mirroring a real CLI process.

func (*Harness) ExecInContainer added in v0.5.0

func (h *Harness) ExecInContainer(agent string, cmd ...string) *RunResult

ExecInContainer runs a command inside an existing container as the container user (claude).

func (*Harness) ExecInContainerAsRoot added in v0.5.0

func (h *Harness) ExecInContainerAsRoot(agent string, cmd ...string) *RunResult

ExecInContainerAsRoot runs a command inside an existing container as root.

func (*Harness) NewIsolatedFS

func (h *Harness) NewIsolatedFS(opts *FSOptions) *SetupResult

NewIsolatedFS creates an isolated test environment.

func (*Harness) RequireServicesWereRunning added in v0.8.0

func (h *Harness) RequireServicesWereRunning(t *testing.T, services ...string)

RequireServicesWereRunning fails the test if the cleanup report shows that the specified services were not running. Callers specify which services they expect — tests using fakes don't call this at all.

Valid service names: "firewall", "controlplane".

func (*Harness) Run

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

Run creates a fresh Factory and executes a CLI command through the full root.NewCmdRoot Cobra pipeline — each call is a fresh process.

func (*Harness) RunInContainer added in v0.5.0

func (h *Harness) RunInContainer(agent string, cmd ...string) *RunResult

RunInContainer runs a command inside a fresh container and returns the result. The container starts, runs the command, and is automatically removed.

type RunResult

type RunResult struct {
	ExitCode int
	Err      error
	Stdout   string
	Stderr   string
	Factory  *cmdutil.Factory
}

RunResult holds the outcome of a CLI command execution.

type SetupResult

type SetupResult struct {
	*testenv.Env
	ProjectDir string
}

SetupResult holds the resolved paths from NewIsolatedFS.

func (*SetupResult) Chdir

func (r *SetupResult) Chdir(t *testing.T, dir string)

Chdir changes the working directory and registers a cleanup to restore it.

Jump to

Keyboard shortcuts

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