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 ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Input ¶ added in v0.1.0
type Input string
Input is the full stdin text fed to a command under test.
type Result ¶
Result holds the captured output and error from a command execution.
func Quick ¶
Quick executes cmd with empty stdin and returns the result.
Example ¶
package main
import (
"fmt"
"strings"
gloo "github.com/gloo-foo/framework"
"github.com/gloo-foo/framework/patterns"
"github.com/gloo-foo/testable/run"
)
// upper upper-cases each input line; it stands in for a real cmd-* command.
func upper() gloo.Command[[]byte, []byte] {
return patterns.Map(func(line []byte) ([]byte, error) {
return []byte(strings.ToUpper(string(line))), nil
})
}
func main() {
res := run.Quick(upper())
fmt.Println(res.Err)
fmt.Println(len(res.Stdout))
}
Output: <nil> 0
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 ¶
Command creates a Runner for cmd with empty stdin and a background context.
Example ¶
package main
import (
"fmt"
"strings"
gloo "github.com/gloo-foo/framework"
"github.com/gloo-foo/framework/patterns"
"github.com/gloo-foo/testable/run"
)
// upper upper-cases each input line; it stands in for a real cmd-* command.
func upper() gloo.Command[[]byte, []byte] {
return patterns.Map(func(line []byte) ([]byte, error) {
return []byte(strings.ToUpper(string(line))), nil
})
}
func main() {
res := run.Command(upper()).WithStdinLines("alpha", "beta").Run()
fmt.Println(res.Err)
fmt.Println(res.Stdout)
}
Output: <nil> [ALPHA BETA]
func WithContext ¶
WithContext (standalone) creates a Runner bound to ctx.
func (Runner) Run ¶
Run executes the configured command and returns the captured result. It is a terminal operation.
func (Runner) WithContext ¶
WithContext returns a copy of the Runner bound to ctx.
func (Runner) WithStdinError ¶
WithStdinError returns a copy of the Runner that fails the input stream with err, for exercising error propagation.
func (Runner) WithStdinLines ¶
WithStdinLines returns a copy of the Runner whose input is lines joined by newlines (each line, including the last, terminated by '\n').