Documentation
¶
Index ¶
- func NewFactory(t *testing.T, opts *FactoryOptions) (*cmdutil.Factory, *bytes.Buffer, *bytes.Buffer, *bytes.Buffer)
- type CleanupReport
- type FSOptions
- type FactoryOptions
- type Harness
- func (h *Harness) ExecInContainer(agent string, cmd ...string) *RunResult
- func (h *Harness) ExecInContainerAsRoot(agent string, cmd ...string) *RunResult
- func (h *Harness) NewIsolatedFS(opts *FSOptions) *SetupResult
- func (h *Harness) RequireServicesWereRunning(t *testing.T, services ...string)
- func (h *Harness) Run(args ...string) *RunResult
- func (h *Harness) RunInContainer(agent string, cmd ...string) *RunResult
- type RunResult
- type SetupResult
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(config.Config, *logger.Logger, project.GitManagerFactory) (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
ExecInContainer runs a command inside an existing container as the container user (claude).
func (*Harness) ExecInContainerAsRoot ¶ added in v0.5.0
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
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".