testecho

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2020 License: MPL-2.0, MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package testecho assists execution of the CLI from test cases and assertion of its result.

Its provides some default inputs for the CLI to support use cases where details such as the exact standard output/error are asserted for equality but semantic content is unnecessary.

Index

Constants

View Source
const (
	// DefaultStdout is the default value for the --stdout flag.
	DefaultStdout = "some stdout message"

	// DefaultStdoutFromStdin is the standard output emitted by testecho when it receives DefaultStdout via
	// standard input.
	//
	// It supports the "testecho | testecho" use case and asserting the final process's behavior.
	DefaultStdoutFromStdin = "stdin [" + DefaultStdout + "]"

	// DefaultStderr is the default value for the --stderr flag.
	DefaultStderr = "some stderr message"

	// DefaultStdoutFromStdinNested is the standard output emitted by testecho when it receives
	// DefaultStdoutFromStdin via standard input.
	//
	// It supports the "testecho | testecho | testecho" use case and asserting the final process's behavior.
	DefaultStdoutFromStdinNested = "stdin [" + DefaultStdoutFromStdin + "]"
)

Variables

This section is empty.

Functions

func NewCmd

func NewCmd(ctx context.Context, i ...Input) *exec.Cmd

NewCmd converts an Input into a command.

It no Input is passed, a zero-valued Input is used. If one Input is passed, it is converted. If multiple Input values are passed, it panics.

func NewCmdArgs

func NewCmdArgs(inputs ...Input) (args []string)

NewCmdArgs converts an Input value into argument strings for use in exec.Command.

It no Input is passed, a zero-valued Input is used. If one Input is passed, it is converted. If multiple Input values are passed, it panics.

func Which

func Which() string

Which returns the absolute path to where the CLI would be installed based on GOPATH.

Types

type Input

type Input struct {
	// Code is the value for the --code flag.
	Code int

	// Stderr is a value for the --sleep flag.
	Sleep int

	// Spawn is true if the command should spawn a child process and block forever (because the child does).
	Spawn bool

	// Stdin is true if the command is expected to receive stdin.
	Stdin bool

	// Stderr is a value for the --stderr flag.
	//
	// If empty, DefaultStderr is used.
	Stderr string

	// Stderr is a value for the --stdout flag.
	//
	// If empty, DefaultStdout is used.
	Stdout string
}

Input defines the CLI flags to use in a testecho invocation.

Jump to

Keyboard shortcuts

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