testutil

package
v3.0.0-...-c77a060 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefGroup = lib.GroupName{Group: "default", Account: "default-account"}

DefGroup is used to return a default group for use in testing

View Source
var DefVM = lib.VirtualMachineName{Group: "default", Account: "default-account"}

DefVM is used to return a default virtual machine for use in testing

Functions

func AssertOutput

func AssertOutput(t *testing.T, app *cli.App, expected string)

AssertOutput fails the test unless the app under test has output exactly the expected string.

func AssertOutputMatches

func AssertOutputMatches(t *testing.T, app *cli.App, expected *regexp.Regexp)

AssertOutputMatches fails the test unless the app under test has produced output which matches the supplied regex.

func BaseTestAuthSetup

func BaseTestAuthSetup(t *testing.T, admin bool, commands []cli.Command) (config *mocks.Config, c *mocks.Client, cliapp *cli.App)

BaseTestAuthSetup sets up a 'regular' test - with auth, no yubikey. user is test-user

func BaseTestSetup

func BaseTestSetup(t *testing.T, admin bool, commands []cli.Command) (conf *mocks.Config, client *mocks.Client, cliapp *cli.App)

BaseTestSetup constructs mock config and client and produces a cli.App with the given commands.

func GetBuf

func GetBuf(app *cli.App) (buf *bytes.Buffer, err error)

GetBuf returns the captured output buffer for the given app. Use this in your tests to find out if your command's output is correct. TODO: add an example

func GetFixtureVM

func GetFixtureVM() brain.VirtualMachine

GetFixtureVM returns a default VM for use in testing

func Name

func Name(iteration int) string

Name returns a sensible name for this test

func TraverseAllCommands

func TraverseAllCommands(cmds []cli.Command, fn func(cli.Command))

TraverseAllCommands goes through all the commands it is supplied.

func TraverseAllCommandsWithContext

func TraverseAllCommandsWithContext(cmds []cli.Command, name string, fn func(fullCommandString string, command cli.Command))

TraverseAllCommandsWithContext adds a more details such as the parent command to commands so we can find the offender easier.

Types

type CommandT

type CommandT struct {
	// Name is the name of the test - passed to t.Run
	Name string
	// Auth is whether the config, client and app should be prepped for
	// authentication
	Auth bool
	// Admin is what we want to stub config.GetBool("admin") to return - i.e.
	// whether the app is in admin-mode.
	Admin bool
	// ShouldErr is whether we're expecting an error to come out of the app.Run
	// call
	ShouldErr bool
	// Args are the command-line arguments to pass to app.Run (after "bytemark")
	Args string
	// Commands are the command set to use in the app. TODO: should I default to
	// main.Commands(Admin)? A: probably
	Commands []cli.Command
	// OutputMustMatch are the regexes the output must match
	OutputMustMatch []*regexp.Regexp
}

CommandT is a representation of all the basic common stuff we tend to end up with in our single-command tests. This helps DRY up tests a bit and should help make writing them faster and less error prone

func (CommandT) Run

func (test CommandT) Run(t *testing.T, setup func(*testing.T, *mocks.Config, *mocks.Client, *cli.App))

Run runs the test. Before setup, it calls t.Run to make a subtest and sets up config, client and app. After setup, it calls app.Run with the args in the CommandT, then checks for errors and verifies the config and client got all the calls they were expecting.

type TestWriter

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

TestWriter is a writer which writes to the test log. This ruins formatting on e.g. text/template renders, but at least it forces all the output to be in order

func (*TestWriter) Write

func (tw *TestWriter) Write(p []byte) (n int, err error)

Write pushes out the bytes as a string to the testing.T instance stored by the TestWriter using t.Log

Jump to

Keyboard shortcuts

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