testenv

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 6 Imported by: 0

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 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

func New(t *testing.T, opts ...Option) *Env

New creates an isolated test environment. It:

  1. Creates temp directories for config, data, state, and cache
  2. Sets CLAWKER_CONFIG_DIR, CLAWKER_DATA_DIR, CLAWKER_STATE_DIR, CLAWKER_CACHE_DIR env vars (restored on test cleanup)
  3. Applies any options (WithConfig, WithProjectManager)

func (*Env) Config

func (e *Env) Config() config.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.

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

type Option func(t *testing.T, e *Env)

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.

Jump to

Keyboard shortcuts

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