test

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2019 License: GPL-2.0, GPL-2.0-or-later Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const Timeout = 3 * time.Second

Timeout is the default duration on the Program Wait timer.

Variables

View Source
var (
	DryRun = flag.Bool("test.dryrun", false,
		"don't run, just print test names")
	MustPause = flag.Bool("test.pause", false,
		"pause before and after suite")
	IsMain = flag.Bool("test.main", false,
		"runs main() instead of test(s)")
	VV  = flag.Bool("test.vv", false, "log test.Program output")
	VVV = flag.Bool("test.vvv", false, "log test.Program execution")
)

Functions

func Carrier

func Carrier(netns, ifname string) error

Assert that named interface has carrier w/in 3sec.

func NoAdjacency

func NoAdjacency(t *testing.T) (err error)

after vlan interface removed, containers deleted, there should be no adjacency rewrites leftover

func Pause

func Pause(args ...interface{})

func PauseQuit

func PauseQuit(t *testing.T)

func Ping

func Ping(netns, addr string) error

Assert ping response to given address w/in 3sec.

Types

type Assert

type Assert struct {
	testing.TB
}

Assert wraps a testing.Test or Benchmark with several assertions.

func (Assert) Background

func (assert Assert) Background(options ...interface{}) *Program

Background Program after asserting that it starts without error. Usage:

defer Assert{t}.Background(...).Quit()

func (Assert) Comment

func (assert Assert) Comment(args ...interface{})

Log args if -test.vv

func (Assert) Commentf

func (assert Assert) Commentf(format string, args ...interface{})

Format args if -test.vv

func (Assert) Dir

func (assert Assert) Dir(name string)

If necessary, change to the dir of the given go package.

func (Assert) Equal

func (assert Assert) Equal(s, expect string)

Equal asserts string equality.

func (Assert) Error

func (assert Assert) Error(err error, v interface{})

Error asserts that an error matches the given error, string, regex, or bool If v is true, asserts err isn't nil; otherwise, if false, asserts that it's nil.

func (Assert) False

func (assert Assert) False(t bool)

False is not True.

func (Assert) Main

func (assert Assert) Main(main func())

Main runs the main function if given the "-test.main" flag. With said flag, this strip os.Args[0] and any leading -test.* options and os.Exit(0) if the main returns. Otherwise, Main changes CWD to "-test.cd", if necessary, and returns.

func (Assert) Match

func (assert Assert) Match(s, pattern string)

Match asserts string pattern match.

func (Assert) MatchNonFatal

func (assert Assert) MatchNonFatal(s, pattern string) bool

Match asserts string pattern match.

func (Assert) Nil

func (assert Assert) Nil(err error)

Nil asserts that there is no error

func (Assert) NoListener

func (assert Assert) NoListener(atsockname string)

Verifiy that there is no listener on named Unix socket.

func (Assert) NonNil

func (assert Assert) NonNil(err error)

NonNil asserts that there is an error

func (Assert) Program

func (assert Assert) Program(options ...interface{})

Program asserts that the Program runs without error.

func (Assert) ProgramErr

func (assert Assert) ProgramErr(v interface{}, options ...interface{})

ProgramErr asserts that the Program returns matches (v) error (see Error).

func (Assert) True

func (assert Assert) True(t bool)

True asserts flag.

func (Assert) YoureRoot

func (assert Assert) YoureRoot()

YoureRoot skips the calling test if EUID != 0

type Cleanup

type Cleanup struct {
	testing.TB
}

Cleanup wraps a testing.Test or Benchmark with Program

func (Cleanup) Program

func (cleanup Cleanup) Program(options ...interface{})

Program runs a cleanup task to its End

type Program

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

Program is an exec.Cmd wrapper

func Begin

func Begin(tb testing.TB, options ...interface{}) (*Program, error)

Begin a Program; type options:

Self	inserts []string{os.Args[0], "-test.main}" into Program args;
	the Test should run it's own main if said flag is set, e.g.:

	func Test(t *testing.T) {
		test.Main(main)
		test.Suite{
			{"Test1", func(t *testing.T) {
				...
			}},
			...
		}.Run(t)
	}

Quiet
	don't log output even if err is !nil
io.Reader
	use reader as Stdin instead of the default, /dev/null

*regexp.Regexp
	match Stdout with compiled regex pattern

time.Duration
	wait up to the given duration for the program to finish instead
	of the default Timeout

func (*Program) End

func (p *Program) End() (err error)

End will wait for Program to finish or timeout then match and log output.

func (*Program) Pid

func (p *Program) Pid() int

Pid returns the program process identifier.

func (*Program) Quit

func (p *Program) Quit()

Quit will SIGTERM the Program then End and Log any error.

type Quiet

type Quiet struct{}

type Self

type Self struct{}

Self flags Program to run itself

type Suite

type Suite struct {
	Name string
	Init func(*testing.T)
	Exit func(*testing.T)
	Tests
}

func (*Suite) Comment

func (suite *Suite) Comment(t *testing.T, args ...interface{})

Log args if -test.vv

func (*Suite) Commentf

func (suite *Suite) Commentf(t *testing.T, format string, args ...interface{})

Format args if -test.vv

func (*Suite) String

func (suite *Suite) String() string

func (Suite) Test

func (suite Suite) Test(t *testing.T)

type Tester

type Tester interface {
	String() string
	Test(*testing.T)
}

type Tests

type Tests []Tester

func (Tests) Test

func (tests Tests) Test(t *testing.T)

type Unit

type Unit struct {
	Name string
	Func func(*testing.T)
}

func (*Unit) String

func (u *Unit) String() string

func (*Unit) Test

func (u *Unit) Test(t *testing.T)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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