test

package module
v1.8.7 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: GPL-2.0, GPL-2.0-or-later Imports: 18 Imported by: 2

README

A collection of test utilities.


© 2015-2020 Platina Systems, Inc. All rights reserved. Use of this source code is governed by this BSD-style LICENSE.

Documentation

Index

Constants

View Source
const (
	Ip4 = "-4"
	Ip6 = "-6"
)

FIXMEIP6: use Stringer or Format?

View Source
const License = `` /* 15871-byte string literal not displayed */
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")
	VV     = flag.Bool("test.vv", false, "log program output")
	VVV    = flag.Bool("test.vvv", false, "log program execution")
	NoGoes = flag.Bool("test.nogoes", false, "linux ip commands")
	NoExec = flag.Bool("test.noexec", false, "stub/echo linux ip commands")
	NoBmc  = flag.Bool("test.nobmc", false, "no redis-cli to bmc")
)
View Source
var (
	Pause = prompt{
		flag.Bool("test.pause", false, "enable program pauses"),
		"pause",
	}
)

Functions

func Carrier

func Carrier(netns, ifname string) error

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

func Comment

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

Log args if -test.vv

func Commentf

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

Format args if -test.vv

func IpFamily

func IpFamily(prefix string) (family string)

func IsIPv6

func IsIPv6(prefix string) (is_ip6 bool)

func Log

func Log() *log.Logger

Log provides a short file style logger to Stdout use in TestMain

func Run

func Run(args ...string)

Run a program - usually from TestMain - and panic if error.

func SkipIfDryRun

func SkipIfDryRun(t *testing.T)

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) 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) Ping

func (assert Assert) Ping(netns, addr string)

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

func (Assert) PingNonFatal

func (assert Assert) PingNonFatal(netns, addr string) bool

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) ProgramNonFatal

func (assert Assert) ProgramNonFatal(options ...interface{}) bool

func (Assert) ProgramRetry

func (assert Assert) ProgramRetry(tries int, options ...interface{})

func (Assert) RetryPing6

func (assert Assert) RetryPing6(xargs []string)

FIXMEIP6: ping6 seems to require retry for validation

func (Assert) True

func (assert Assert) True(t bool)

True asserts flag.

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

func (Cleanup) ProgramRetry added in v1.8.6

func (cleanup Cleanup) ProgramRetry(tries int, options ...interface{})

type Daemon

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

A Daemon is a background program started and defer stopped from a TestMain.

func (*Daemon) Pid

func (d *Daemon) Pid() int

func (*Daemon) Start

func (d *Daemon) Start(args ...string)

Start the daemon program and panic if error.

func (*Daemon) Stop

func (d *Daemon) Stop()

Stop the running daemon with a TERM, INT, then KILL signal

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:

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 Suite

type Suite struct {
	Name string
	Tests
}

A Suite is a named set of tests

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)

Directories

Path Synopsis
Package ethtool parses testdata/ethtool.yaml and testdata/ethtool_priv_flags.yaml; then issues the respective commands.
Package ethtool parses testdata/ethtool.yaml and testdata/ethtool_priv_flags.yaml; then issues the respective commands.
Package netport parses testdata/netport.yaml for interface assingments along with utilities to build and test virtual networks configured from these assignments.
Package netport parses testdata/netport.yaml for interface assingments along with utilities to build and test virtual networks configured from these assignments.

Jump to

Keyboard shortcuts

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