Documentation
¶
Overview ¶
Package testenv provides unified, progressively-configured test environments for isolated filesystem tests. It creates temp directories for all four XDG categories (config, data, state, cache), sets the corresponding CLAWKER_*_DIR env vars, and optionally wires up a real config.Config and/or ProjectManager.
Usage:
// Just isolated dirs (storage tests): env := testenv.New(t) env.Dirs.Data // absolute path // With real config (config, socketbridge tests): env := testenv.New(t, testenv.WithConfig()) env.Config() // config.Config backed by temp dirs // With real project manager (project tests): env := testenv.New(t, testenv.WithProjectManager(nil)) env.ProjectManager() // project.ProjectManager env.Config() // also available — PM implies Config
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigFile ¶ added in v0.5.0
type ConfigFile int
ConfigFile identifies a configuration file type and its canonical location.
const ( // ProjectConfig writes .clawker.yaml to the given directory (dotfile placement). ProjectConfig ConfigFile = iota // ProjectConfigLocal writes .clawker.local.yaml to the given directory (highest priority). ProjectConfigLocal // Settings writes settings.yaml to the config directory. Settings // EgressRules writes egress-rules.yaml to the state directory. EgressRules // ProjectRegistry writes projects.yaml to the data directory. ProjectRegistry )
type Env ¶
type Env struct {
Dirs IsolatedDirs
// contains filtered or unexported fields
}
Env is a unified test environment with isolated directories and optional higher-level capabilities (config, project manager).
func New ¶
New creates an isolated test environment. It:
- Creates temp directories for config, data, state, and cache
- Sets CLAWKER_CONFIG_DIR, CLAWKER_DATA_DIR, CLAWKER_STATE_DIR, CLAWKER_CACHE_DIR env vars (restored on test cleanup)
- Applies any options (WithConfig, WithProjectManager)
func (*Env) Config ¶
Config returns the config.Config. Panics if WithConfig (or WithProjectManager) was not passed to New.
func (*Env) ProjectManager ¶
func (e *Env) ProjectManager() project.ProjectManager
ProjectManager returns the project.ProjectManager. Panics if WithProjectManager was not passed to New.
func (*Env) WriteYAML ¶ added in v0.5.0
WriteYAML writes YAML content to the canonical location for the given file type.
For project config files (ProjectConfig, ProjectConfigLocal), dir specifies the project directory where the dotfile will be created. For all other file types, dir is ignored and the appropriate XDG directory is used.
env.WriteYAML(t, testenv.ProjectConfig, projectDir, `agent: { claude_code: { use_host_auth: false } }`)
env.WriteYAML(t, testenv.Settings, "", `firewall: { enable: false }`)
type IsolatedDirs ¶
type IsolatedDirs struct {
Base string // temp root (parent of all dirs)
Config string // CLAWKER_CONFIG_DIR
Data string // CLAWKER_DATA_DIR
State string // CLAWKER_STATE_DIR
Cache string // CLAWKER_CACHE_DIR
}
IsolatedDirs holds the four XDG-style directory paths created for the test.
type Option ¶
Option configures an Env during construction.
func WithConfig ¶
func WithConfig() Option
WithConfig creates a real config.Config backed by the isolated directories. The config is available via env.Config().
func WithProjectManager ¶
func WithProjectManager(gitFactory project.GitManagerFactory) Option
WithProjectManager creates a real project.ProjectManager backed by the isolated directories. Implies WithConfig. Pass nil for gitFactory if worktree operations are not needed.