exectest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FailingTTYHandler

func FailingTTYHandler(err error) exec.TTYHandlerFunc

FailingTTYHandler returns a TTYHandlerFunc that immediately returns an error.

func FakeTerminalFactory

func FakeTerminalFactory(ft *FakeTerminal) exec.TerminalFactory

FakeTerminalFactory returns an exec.TerminalFactory that creates the given FakeTerminal on the first call and returns an error on subsequent calls. If ft is nil, the factory always returns (nil, os.ErrClosed).

func NewFakeTerminalFactory

func NewFakeTerminalFactory() exec.TerminalFactory

NewFakeTerminalFactory returns a factory that creates a fresh FakeTerminal each time it is called.

func NoopTTYHandler

func NoopTTYHandler() exec.TTYHandlerFunc

NoopTTYHandler returns a TTYHandlerFunc that does nothing — the session stays open until context cancellation or stopCh signal.

func StopChTTYHandler

func StopChTTYHandler(stopErr error, delay time.Duration) exec.TTYHandlerFunc

StopChTTYHandler returns a TTYHandlerFunc that sends the given error on the stopCh after a delay, simulating a handler that fails after starting. The send is non-blocking so the goroutine never leaks if the session ends early. A deferred recover guards against sends on a closed channel.

Types

type FakeTerminal

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

FakeTerminal implements exec.Terminal using os.Pipe pairs. This allows tests to inject data into the master side and read from the slave side without requiring real PTY support.

func NewFakeTerminal

func NewFakeTerminal() (*FakeTerminal, error)

NewFakeTerminal creates a FakeTerminal backed by two os.Pipe pairs.

func (*FakeTerminal) Close

func (t *FakeTerminal) Close() error

func (*FakeTerminal) InjectOutput

func (t *FakeTerminal) InjectOutput(data []byte) (int, error)

InjectOutput writes data to the master write end, simulating PTY output that the manager will read from MasterFd().

func (*FakeTerminal) MasterFd

func (t *FakeTerminal) MasterFd() *os.File

func (*FakeTerminal) Resize

func (t *FakeTerminal) Resize(rows, cols uint16) error

func (*FakeTerminal) Resizes

func (t *FakeTerminal) Resizes() []ResizeRecord

Resizes returns a copy of all resize records.

func (*FakeTerminal) SlaveFd

func (t *FakeTerminal) SlaveFd() *os.File

type Harness

type Harness struct {
	Manager *exec.Manager
	Output  *RecordingOutput
	// contains filtered or unexported fields
}

Harness is a test DSL wrapping a real exec.Manager with fake terminals.

func Mount

func Mount(t *testing.T, opts ...HarnessOption) *Harness

Mount creates a new Harness. The harness is automatically cleaned up via t.Cleanup().

func (*Harness) AttachSession

func (h *Harness) AttachSession(sessionID string) (*exec.Session, []byte, error)

AttachSession attaches to a session.

func (*Harness) CloseSession

func (h *Harness) CloseSession(sessionID string) error

CloseSession closes a session by ID.

func (*Harness) CreateSession

func (h *Harness) CreateSession(opts exec.SessionOptions) (*exec.Session, error)

CreateSession creates a session using the harness context.

func (*Harness) DetachSession

func (h *Harness) DetachSession(sessionID string) (*exec.Session, error)

DetachSession detaches from a session.

func (*Harness) GetSession

func (h *Harness) GetSession(sessionID string) (*exec.Session, error)

GetSession retrieves a session by ID.

func (*Harness) WaitForClose

func (h *Harness) WaitForClose(timeout time.Duration) *exec.StreamOutput

WaitForClose blocks until the close signal for a session is emitted.

type HarnessOption

type HarnessOption func(*harnessConfig)

HarnessOption configures a Harness.

func WithClock

func WithClock(clk timeutil.Clock) HarnessOption

WithClock injects a custom clock.

func WithHandler

func WithHandler(h exec.Handler) HarnessOption

WithHandler registers a handler with the harness.

func WithLogger

func WithLogger(l logging.Logger) HarnessOption

WithLogger sets a custom logger.

func WithTerminalFactory

func WithTerminalFactory(tf exec.TerminalFactory) HarnessOption

WithTerminalFactory overrides the terminal factory.

type RecordingOutput

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

RecordingOutput implements exec.OutputSink by recording all output. Thread-safe, with WaitFor* helpers for test assertions.

func NewRecordingOutput

func NewRecordingOutput() *RecordingOutput

NewRecordingOutput creates a new RecordingOutput.

func (*RecordingOutput) AllData

func (r *RecordingOutput) AllData() []byte

AllData concatenates all data from non-signal outputs.

func (*RecordingOutput) Count

func (r *RecordingOutput) Count() int

Count returns the number of recorded outputs.

func (*RecordingOutput) DataOutputs

func (r *RecordingOutput) DataOutputs() []exec.StreamOutput

DataOutputs returns only the outputs that have non-zero data and no signal.

func (*RecordingOutput) OnOutput

func (r *RecordingOutput) OnOutput(output exec.StreamOutput)

func (*RecordingOutput) Outputs

func (r *RecordingOutput) Outputs() []exec.StreamOutput

Outputs returns a copy of all recorded outputs.

func (*RecordingOutput) WaitForOutputs

func (r *RecordingOutput) WaitForOutputs(count int, timeout time.Duration) []exec.StreamOutput

WaitForOutputs blocks until at least count outputs have been recorded, or the timeout expires.

func (*RecordingOutput) WaitForSignal

func (r *RecordingOutput) WaitForSignal(signal exec.StreamSignal, timeout time.Duration) *exec.StreamOutput

WaitForSignal blocks until an output with the given signal is recorded, or the timeout expires.

type ResizeRecord

type ResizeRecord struct {
	Rows uint16
	Cols uint16
}

ResizeRecord captures a resize call.

Jump to

Keyboard shortcuts

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