Documentation
¶
Index ¶
- type Pipeline
- type PipelineResult
- type PipelineStage
- type Process
- func (p *Process) CaptureStderr() *bytes.Buffer
- func (p *Process) CaptureStdout() *bytes.Buffer
- func (p *Process) Close() error
- func (p *Process) Run(ctx context.Context) *ProcessResult
- func (p *Process) RunWithIO(ctx context.Context, r io.Reader) *ProcessResult
- func (p *Process) SetArgs(args []string)
- func (p *Process) SetStderr(w io.Writer)
- func (p *Process) SetStdin(r io.Reader)
- func (p *Process) SetStdout(w io.Writer)
- func (p *Process) StderrPipe() io.Reader
- func (p *Process) StdoutPipe() io.Reader
- func (p *Process) Write(b []byte) (int, error)
- type ProcessResult
- type Runner
- type Sandbox
- func (sandbox *Sandbox) AbsPath(rel string) string
- func (sandbox *Sandbox) Advance(d time.Duration)
- func (sandbox *Sandbox) AtomicWriteFile(rel string, data []byte, perm os.FileMode) error
- func (sandbox *Sandbox) Context() context.Context
- func (sandbox *Sandbox) DumpJailTree(maxDepth int)
- func (sandbox *Sandbox) GetHome() (string, error)
- func (sandbox *Sandbox) GetJail() string
- func (sandbox *Sandbox) Getwd() string
- func (sandbox *Sandbox) Mkdir(rel string, all bool) error
- func (sandbox *Sandbox) MustReadFile(rel string) []byte
- func (sandbox *Sandbox) MustWriteFile(path string, data []byte, perm os.FileMode)
- func (sandbox *Sandbox) Now() time.Time
- func (sandbox *Sandbox) ReadFile(rel string) ([]byte, error)
- func (sandbox *Sandbox) ResolvePath(rel string) string
- func (sandbox *Sandbox) Setwd(dir string)
- func (sandbox *Sandbox) WriteFile(rel string, data []byte, perm os.FileMode) error
- type SandboxOption
- type SandboxOptions
- type StageOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline manages execution of multiple stages with piped I/O.
func NewPipeline ¶
func NewPipeline(stages ...*PipelineStage) *Pipeline
NewPipeline constructs a Pipeline with the given stages.
func (*Pipeline) CaptureStderr ¶
CaptureStderr configures stderr capture and returns the buffer.
func (*Pipeline) CaptureStdout ¶
CaptureStdout configures stdout capture and returns the buffer.
func (*Pipeline) Run ¶
func (p *Pipeline) Run(ctx context.Context) *PipelineResult
Run executes all stages in the pipeline sequentially with stdout piped from each stage to stdin of the next. Returns a PipelineResult containing any errors and captured output.
func (*Pipeline) RunWithTimeout ¶
RunWithTimeout executes the pipeline with a deadline. If the deadline is exceeded before completion, execution is cancelled and context.DeadlineExceeded is returned in the result.
type PipelineResult ¶
PipelineResult holds the outcome of pipeline execution.
type PipelineStage ¶
type PipelineStage struct {
// contains filtered or unexported fields
}
PipelineStage represents a single stage in a pipeline.
func Stage ¶
func Stage(name string, runner Runner) *PipelineStage
Stage constructs a PipelineStage with the given name and runner.
func StageWithName ¶
func StageWithName(name string, p *Process) *PipelineStage
StageWithName constructs a PipelineStage with the given name, wrapping the provided Process.
type Process ¶
type Process struct {
// contains filtered or unexported fields
}
Process manages execution of a Runner function with configurable I/O streams and piping support. It allows tests to run functions in isolation with piped input/output between multiple processes.
func NewProcess ¶
NewProcess constructs a Process bound to a Runner function with the specified TTY mode. The context parameter is reserved for future use.
func NewProducer ¶
NewProducer constructs a Process that emits the provided byte buffer to stdout. It is useful for testing stages that consume input.
func (*Process) CaptureStderr ¶
CaptureStderr configures stderr capture and returns the buffer.
func (*Process) CaptureStdout ¶
CaptureStdout configures stdout capture and returns the buffer.
func (*Process) Close ¶
Close closes the process stdin writer. This signals EOF to the process, allowing it to complete reading.
func (*Process) Run ¶
func (p *Process) Run(ctx context.Context) *ProcessResult
Run executes the process runner synchronously. It wires configured streams, invokes the runner with the provided arguments, and closes any process-owned writers and readers when complete. Returns a ProcessResult containing the exit code, error, and captured output.
func (*Process) StderrPipe ¶
StderrPipe returns a reader connected to the process stderr. Writing to the process stderr will be readable from the returned reader.
func (*Process) StdoutPipe ¶
StdoutPipe returns a reader connected to the process stdout. Writing to the process stdout will be readable from the returned reader.
type ProcessResult ¶
ProcessResult holds the outcome of process execution including any error, exit code, and captured stdout and stderr output.
type Runner ¶
Runner is a function signature for executing code within an isolated test environment. It receives a context, standard I/O streams, and command-line arguments, returning an error on failure.
type Sandbox ¶
type Sandbox struct {
// contains filtered or unexported fields
}
Sandbox bundles common test setup used by package tests. It contains a testing.T, a context carrying a test logger, a test env, a test clock, a hasher, and a temporary "jail" directory that acts as an isolated filesystem.
func NewSandbox ¶
func NewSandbox(t *testing.T, options *SandboxOptions, opts ...SandboxOption) *Sandbox
NewSandbox constructs a Sandbox and applies given options. Cleanup is registered with t.Cleanup so callers do not need to call a cleanup function.
func (*Sandbox) AbsPath ¶
AbsPath returns an absolute path. When the sandbox Jail is set and rel is relative the path is made relative to the Jail. Otherwise the function returns the absolute form of rel.
func (*Sandbox) AtomicWriteFile ¶
func (*Sandbox) DumpJailTree ¶
DumpJailTree logs a tree of files and directories rooted at the sandbox's Jail. Only directories with no children and files are logged. maxDepth limits recursion depth; maxDepth <= 0 means unlimited depth.
func (*Sandbox) MustReadFile ¶
MustReadFile reads a file under the Jail and fails the test on error.
func (*Sandbox) MustWriteFile ¶
MustWriteFile writes data under the Jail and fails the test on error.
func (*Sandbox) ReadFile ¶
ReadFile reads a file located under the sandbox Jail. The path is interpreted relative to the Jail root.
func (*Sandbox) ResolvePath ¶
ResolvePath returns an absolute path with symlinks resolved, ensuring the path remains within the sandbox Jail. It expands the path and evaluates any symbolic links before confining it to the jail boundary.
type SandboxOption ¶
type SandboxOption func(f *Sandbox)
SandboxOption is a function used to modify a Sandbox during construction.
func WithClock ¶
func WithClock(t0 time.Time) SandboxOption
WithClock returns a SandboxOption that sets the test clock to the provided time.
func WithEnv ¶
func WithEnv(key, val string) SandboxOption
WithEnv returns a SandboxOption that sets a single environment variable in the sandbox's Env.
func WithEnvMap ¶
func WithEnvMap(m map[string]string) SandboxOption
WithEnvMap returns a SandboxOption that seeds multiple environment variables from a map.
func WithFixture ¶
func WithFixture(fixture string, path string) SandboxOption
WithFixture returns a SandboxOption that copies a fixture directory from the embedded package data into the provided path within the sandbox Jail. Example fixtures are "empty" or "example".
func WithWd ¶
func WithWd(rel string) SandboxOption
WithWd returns a SandboxOption that sets the sandbox working directory.
type SandboxOptions ¶
type SandboxOptions struct {
// Data is an embedded filesystem containing test fixtures.
Data embed.FS
// Home is the home directory for the user. If empty defaults to
// /home/$USER. If the user is root the default is /.root.
Home string
// User is the username. Defaults to testuser.
User string
}
SandboxOptions holds optional settings provided to NewSandbox.