capture

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer captures output into a thread-safe buffer for testing. Use this to verify command output in tests.

func NewBuffer

func NewBuffer() *Buffer

NewBuffer creates a new output buffer.

func (*Buffer) Clear

func (b *Buffer) Clear()

Clear removes all captured output.

func (*Buffer) Count

func (b *Buffer) Count() int

Count returns the number of lines captured.

func (*Buffer) Lines

func (b *Buffer) Lines() []string

Lines returns all captured output lines.

func (*Buffer) String

func (b *Buffer) String() string

String returns all captured output as a single string with newlines.

func (*Buffer) Write

func (b *Buffer) Write(output string) error

Write captures a single line of output.

type ErrorInjector

type ErrorInjector struct {
	// contains filtered or unexported fields
}

ErrorInjector returns an error after a specified number of writes. Useful for testing error handling in output paths.

func NewErrorInjector

func NewErrorInjector(wrapped OutputFunc, errorAt int, err error) *ErrorInjector

NewErrorInjector creates an OutputFunc that injects an error at a specific call.

func (*ErrorInjector) Write

func (e *ErrorInjector) Write(output string) error

Write delegates to the wrapped function until the error point is reached.

type OutputFunc

type OutputFunc func(output string) error

OutputFunc is a function type that writes output. This abstraction enables testing by allowing output to be captured or redirected without depending on concrete io.Writer implementations.

func StderrFunc

func StderrFunc(w io.Writer) OutputFunc

StderrFunc creates an OutputFunc that writes to an io.Writer with newlines. Identical to StdoutFunc but semantically distinct for stderr.

func StdoutFunc

func StdoutFunc(w io.Writer) OutputFunc

StdoutFunc creates an OutputFunc that writes to an io.Writer with newlines. This is the standard implementation for production use.

type Tee

type Tee struct {
	// contains filtered or unexported fields
}

Tee writes output to multiple OutputFuncs simultaneously. Similar to Unix tee command, useful for capturing output while still displaying it.

func NewTee

func NewTee(outputs ...OutputFunc) *Tee

NewTee creates an OutputFunc that writes to multiple destinations.

func (*Tee) Write

func (t *Tee) Write(output string) error

Write sends output to all wrapped OutputFuncs. Returns the first error encountered, but attempts all writes.

Jump to

Keyboard shortcuts

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