Documentation ¶
Index ¶
- Variables
- func AssertOutput(t *testing.T, app *cli.App, expected string)
- func AssertOutputMatches(t *testing.T, app *cli.App, expected *regexp.Regexp)
- func BaseTestAuthSetup(t *testing.T, admin bool, commands []cli.Command) (config *mocks.Config, c *mocks.Client, cliapp *cli.App)
- func BaseTestSetup(t *testing.T, admin bool, commands []cli.Command) (conf *mocks.Config, client *mocks.Client, cliapp *cli.App)
- func GetBuf(app *cli.App) (buf *bytes.Buffer, err error)
- func GetFixtureVM() brain.VirtualMachine
- func Name(iteration int) string
- func TraverseAllCommands(cmds []cli.Command, fn func(cli.Command))
- func TraverseAllCommandsWithContext(cmds []cli.Command, name string, ...)
- type CommandT
- type TestWriter
Constants ¶
This section is empty.
Variables ¶
var DefGroup = lib.GroupName{Group: "default", Account: "default-account"}
DefGroup is used to return a default group for use in testing
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 ¶
AssertOutput fails the test unless the app under test has output exactly the expected string.
func AssertOutputMatches ¶
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 ¶
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 TraverseAllCommands ¶
TraverseAllCommands goes through all the commands it is supplied.
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