run

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

Overview

Package run provides a small fluent harness for exercising a Command[[]byte, []byte] in tests: configure stdin, run, and inspect the captured output lines and error.

res := run.Command(myCmd).WithStdinLines("a", "b").Run()
// res.Stdout == []string{...}, res.Err == nil

It complements the package-level testable.Test / testable.TestLines helpers with explicit input control (custom readers, injected read errors).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	Stdout []string // Output lines (the command's output stream)
	Err    error    // First error carried by the stream, if any
}

Result holds the captured output and error from a command execution.

func Quick

func Quick(cmd gloo.Command[[]byte, []byte]) *Result

Quick executes cmd with empty stdin and returns the result.

func WithInput

func WithInput(cmd gloo.Command[[]byte, []byte], stdin string) *Result

WithInput executes cmd with the given stdin string and returns the result.

type Runner

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

Runner configures and executes a command for testing. Every With* method returns a NEW Runner, so a Runner is immutable and safe to reuse.

func Command

func Command(cmd gloo.Command[[]byte, []byte]) Runner

Command creates a Runner for cmd with empty stdin and a background context.

func WithContext

func WithContext(ctx context.Context, cmd gloo.Command[[]byte, []byte]) Runner

WithContext (standalone) creates a Runner bound to ctx.

func (Runner) Run

func (r Runner) Run() *Result

Run executes the configured command and returns the captured result. It is a terminal operation.

func (Runner) WithContext

func (r Runner) WithContext(ctx context.Context) Runner

WithContext returns a copy of the Runner bound to ctx.

func (Runner) WithStdin

func (r Runner) WithStdin(input string) Runner

WithStdin returns a copy of the Runner whose input is input.

func (Runner) WithStdinError

func (r Runner) WithStdinError(err error) Runner

WithStdinError returns a copy of the Runner that fails the input stream with err, for exercising error propagation.

func (Runner) WithStdinLines

func (r Runner) WithStdinLines(lines ...string) Runner

WithStdinLines returns a copy of the Runner whose input is lines joined by newlines (each line, including the last, terminated by '\n').

func (Runner) WithStdinReader

func (r Runner) WithStdinReader(reader io.Reader) Runner

WithStdinReader returns a copy of the Runner reading input from reader.

Jump to

Keyboard shortcuts

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