testable

package module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 3 Imported by: 0

README

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

func Test(cmd gloo.Command[[]byte, []byte], input run.Input) (string, error)

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

func TestLines(cmd gloo.Command[[]byte, []byte], input run.Input) ([]string, error)

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.

Jump to

Keyboard shortcuts

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