Documentation
¶
Overview ¶
Package harness provides utilities for running cog integration tests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolveCogBinary ¶
ResolveCogBinary finds the cog binary to use for tests. It checks (in order): 1. COG_BINARY environment variable 2. Build from source (if in cog repository)
Types ¶
type Command ¶
type Command interface {
// Name returns the command name as used in txtar scripts.
Name() string
// Run executes the command.
// neg is true if the command was prefixed with '!' (expecting failure).
// args are the command arguments.
Run(ts *testscript.TestScript, neg bool, args []string)
}
Command defines the interface for testscript commands.
func NewCommand ¶
func NewCommand(name string, fn func(ts *testscript.TestScript, neg bool, args []string)) Command
NewCommand creates a Command from a name and function.
type CommandFunc ¶
type CommandFunc struct {
// contains filtered or unexported fields
}
CommandFunc adapts a function to the Command interface.
func (CommandFunc) Name ¶
func (c CommandFunc) Name() string
func (CommandFunc) Run ¶
func (c CommandFunc) Run(ts *testscript.TestScript, neg bool, args []string)
type Harness ¶
type Harness struct {
CogBinary string
// contains filtered or unexported fields
}
func (*Harness) Commands ¶
func (h *Harness) Commands() map[string]func(ts *testscript.TestScript, neg bool, args []string)
Commands returns the custom testscript commands provided by this harness.
func (*Harness) Setup ¶
func (h *Harness) Setup(env *testscript.Env) error
Setup returns a testscript Setup function that configures the test environment. Fixtures are embedded in the txtar files themselves, so no file copying is needed.
func (*Harness) StopServer ¶
func (h *Harness) StopServer(ts *testscript.TestScript)
StopServer stops the background server process for a test script.
type PtyRunCommand ¶
type PtyRunCommand struct {
// contains filtered or unexported fields
}
PtyRunCommand implements the 'pty-run' command for testscript.
func (*PtyRunCommand) Name ¶
func (c *PtyRunCommand) Name() string
func (*PtyRunCommand) Run ¶
func (c *PtyRunCommand) Run(ts *testscript.TestScript, neg bool, args []string)
Run executes a command with a PTY, sending input from a file and capturing output.
Usage: pty-run <input-file> <command> [args...]
The input file contents are written to the PTY as terminal input. Use /dev/null or an empty file if no input is needed. The command's output is written to stdout for matching with 'stdout' command.
This uses github.com/creack/pty which works on both Linux and macOS, unlike testscript's native ttyin/ttyout which hangs on macOS due to Go bug https://github.com/golang/go/issues/61779.
TODO: Remove this implementation and use testscript's native ttyin/ttyout once the Go bug is fixed (check Go 1.26+).