Documentation
¶
Overview ¶
Package testable is the shared test harness for gloo-foo commands. It runs a Command[[]byte, []byte] against in-memory input and returns the captured output, so a command can be tested without touching real files or I/O.
Test and TestLines are the convenience entry points used by the cmd-* modules. They delegate to the fn package — the production adapter that runs a command as an ordinary data function — so a command behaves identically under test and in use. The run subpackage offers a fluent Runner for finer control (custom readers, injected read errors, an explicit context).
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Test ¶
Test runs cmd with the given input and returns its captured stdout as a single string, each output line terminated by '\n'. On command failure it returns the error and an empty string.
Example ¶
package main
import (
"fmt"
"strings"
gloo "github.com/gloo-foo/framework"
"github.com/gloo-foo/framework/patterns"
"github.com/gloo-foo/testable"
)
// 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() {
out, err := testable.Test(upper(), "hello\nworld\n")
fmt.Printf("%q\n", out)
fmt.Println(err)
}
Output: "HELLO\nWORLD\n" <nil>
func TestLines ¶
TestLines runs cmd with the given input and returns its captured stdout as lines. On command failure it returns the error and a nil slice.
Example ¶
package main
import (
"fmt"
"strings"
gloo "github.com/gloo-foo/framework"
"github.com/gloo-foo/framework/patterns"
"github.com/gloo-foo/testable"
)
// 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() {
lines, err := testable.TestLines(upper(), "hello\nworld\n")
fmt.Println(err)
fmt.Println(lines)
}
Output: <nil> [HELLO WORLD]
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
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.
|
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. |