testhelper

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	OmitThisFlag  = "<OMIT_THIS_FLAG>"
	OmitFlagValue = "<OMIT_FLAG_VALUE>"
)

Variables

This section is empty.

Functions

func Error added in v0.8.0

func Error() error

Error returns an internal error for testing

func HijackStandardStreams added in v0.8.0

func HijackStandardStreams(stdin, stdout, stderr *os.File, do func())

func NewAlwaysErrFS added in v0.8.0

func NewAlwaysErrFS(err error) fs.FS

NewAlwaysErrFS creates an fs.FS that always fail at Open() call with provided err

if err is nil, fs.ErrInvalid is returned by default

func NewAlwaysFailReader added in v0.8.0

func NewAlwaysFailReader(err error) io.Reader

NewAlwaysFailReader creates an reader already fail on Read() call with provided err

if err is nil, an io.ErrUnexpectedEOF is returned by default

func TestCmdFixtures added in v0.8.1

func TestCmdFixtures(t *testing.T,
	dir string,
	flagMatrix map[string][]string,
	genNewSpec func(
		flagSets [][]string, baseSpec *CmdTestCase, baseCheck *CmdTestCheckSpec,
	) (*CmdTestCase, *CmdTestCheckSpec),
	prepareRun func(flags []string) (checkFlags func() error, runCmd func() error, _ error),
)

func TestFixtures

func TestFixtures(
	t *testing.T,
	dir string,
	createTestSpec func() interface{},
	createExpected func() interface{},
	check func(t *testing.T, spec interface{}, exp interface{}),
)

TestFixtures run tests using multi-doc yaml file

# first doc is the test spec some_args: ... spec:

a: b

--- # second doc is the expected result c: d

Types

type CmdTestCase added in v0.8.1

type CmdTestCase struct {
	rs.BaseField

	// Flags is the command line flags to cmd, including positional args
	Flags []string `yaml:"flags"`

	// Stdin is the input to cmd stdin
	Stdin string `yaml:"stdin"`
}

type CmdTestCheckSpec added in v0.8.1

type CmdTestCheckSpec struct {
	rs.BaseField

	// BadFlags expects optoins and/or args are invalid
	BadFlags bool `yaml:"bad_flags"`

	// BadCmd expects cmd run error
	//
	// after parsing all flags and before checking output
	BadCmd bool `yaml:"bad_cmd"`

	// Stdout is the expected output to stdout
	Stdout string `yaml:"stdout"`

	// Stderr is the expected output to stderr
	Stderr string `yaml:"stderr"`
}

Jump to

Keyboard shortcuts

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