shelltest

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2019 License: MIT Imports: 18 Imported by: 0

README

Shelltest

This package wraps testing and provides an interface to run commands in a persistent shell.

Testing

Testing this is tricky. Its tests (at the moment) fail on purpose - run with -tags=shelltesttest to get them

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPath

func BuildPath(exes ...string) (string, error)

BuildPath constructs a PATH that includes the directories with given exectuables in them.

func TemplateConfigs

func TemplateConfigs(sourceDir, targetDir string, configData interface{}) error

TemplateConfigs walks the sourceDir, templating into targetDir based on configData

func WithHostEnv

func WithHostEnv(hostEnvs []string, env map[string]string) map[string]string

WithHostEnv copies values from the host system into an env map, merging given values in.

Types

type CheckFn

type CheckFn func(string, Result, *testing.T)

A CheckFn receives the Result of running a script, and should inspect it, calling methods on the testing.T as appropriate

type Result

type Result struct {
	Script                             string
	Exit                               int
	Stdout, Stderr, Blended, Env, Errs string
}

A Result captures the output of a shell run

func (Result) ErrsMatches

func (res Result) ErrsMatches(pattern string) bool

ErrsMatches asserts that the Errs stream matches a regex pattern - for instance to check that a particular command fails.

func (Result) Matches

func (res Result) Matches(pattern string) bool

Matches asserts that the stdout of the result matches a regex pattern

func (Result) StderrMatches

func (res Result) StderrMatches(pattern string) bool

StderrMatches asserts that the stdout of the result matches a regex pattern

func (Result) StdoutMatches

func (res Result) StdoutMatches(pattern string) bool

StdoutMatches asserts that the stdout of the result matches a regex pattern

func (Result) WriteTo

func (res Result) WriteTo(dir, base string) error

WriteTo writes details of this result to a particular path

type ShellTest

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

A ShellTest is a context for executing CLI commands and testing the results

func New

func New(t *testing.T, name string, ctx interface{}, env map[string]string) *ShellTest

New creates a new ShellTest

func (*ShellTest) Block

func (st *ShellTest) Block(name, oldScript string, check ...CheckFn) *ShellTest

Block runs a block of shell script, returning a new ShellTest. If the check function includes a failing test, however, blocks run on the resulting ShellTest will be skipped.

func (*ShellTest) DebugPrefix

func (st *ShellTest) DebugPrefix(prefix string)

DebugPrefix directs the ShellTest to write all received bytes to debug files in TempDir/Prefix

func (*ShellTest) Template

func (st *ShellTest) Template(name, tmplSrc string) (string, error)

Template processes a tmplSrc as a text/template with the ShellTest's template context. Useful for user advice, for instance.

func (*ShellTest) WriteTo

func (st *ShellTest) WriteTo(dir string) error

WriteTo directs the ShellTest to write details of its execution into the passed directory.

Jump to

Keyboard shortcuts

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