cmd

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: Apache-2.0, MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// When this environ var is set to a value and running tests with -v flag,
	// then Runner output is logged.
	EnvTestRunnerOutput = "TEST_RUNNER_OUTPUT"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CmdArgs

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

CmdArgs contains a command name and any arguments.

func Args

func Args(name string, args ...string) CmdArgs

Args creates a CmdArgs instance with the given command name and args. This is used to supply the command names and args to Start.

func (CmdArgs) String

func (a CmdArgs) String() string

type Runner

type Runner struct {
	Dir string
	Env []string
	// contains filtered or unexported fields
}

Runner is a helper for running the indexer and other commands. Runner is not specifically tied to the indexer, but is designed to be used to manage multiple processes in a test; and is therefore useful for testing the indexer, the dhstore, and providers, all in a temporary directory and with a test environment.

func NewRunner

func NewRunner(t *testing.T, dir string) *Runner

NewRunner creates a new Runner for the given test, context, and temporary directory. It also takes a list of StdoutWatchers, which will be used to watch for specific output from the commands.

func (*Runner) Run

func (rnr *Runner) Run(ctx context.Context, name string, args ...string) []byte

Run runs a command and returns its output. This is useful for executing synchronous commands within the temporary environment.

func (*Runner) Start

func (rnr *Runner) Start(ctx context.Context, args CmdArgs, watchers ...Watcher) *exec.Cmd

Start starts and returns the command. This is useful for executing asynchronous commands within the temporary environment. If any watchers are supplied, the command's stdout is scanned to look for any matches and signal the corresponding watchers.

func (*Runner) Stop

func (rnr *Runner) Stop(cmd *exec.Cmd, timeout time.Duration)

Stop stops a command. It sends SIGINT, and if that does not work, SIGKILL.

type Watcher added in v0.0.4

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

Watcher is a helper for watching a command's output for a specific string. The watcher can watch stdout, stderr or both. It is used by Runner to watch for specific output from the commands. The Signal channel is signaled when the match string is found.

func NewStderrWatcher added in v0.0.4

func NewStderrWatcher(match string) Watcher

NewStderrWatcher creates a Watcher that is signeled when matching a string from stderr.

func NewStdoutWatcher

func NewStdoutWatcher(match string) Watcher

NewStdoutWatcher creates a Watcher that is signeled when matching a string from stdout.

func NewWatcher added in v0.0.4

func NewWatcher(match string) Watcher

NewWatcher creates a Watcher that is signeled when matching a string from stderr or stdout.

func (Watcher) Signal added in v0.0.4

func (w Watcher) Signal() <-chan struct{}

Signal returns the channel that is signaled when a line of output matches this watcher.

func (Watcher) Wait added in v0.0.4

func (w Watcher) Wait(ctx context.Context) error

Wait waits for the watcher to be signaled for the the context to be canceled. If the context is canceled then the context error is returned.

Jump to

Keyboard shortcuts

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