Documentation ¶
Index ¶
- Constants
- Variables
- func AssertEchoArgs(c *gc.C, execName string, args ...string)
- func HookCommandOutput(outputFunc *func(cmd *exec.Cmd) ([]byte, error), output []byte, err error) (<-chan *exec.Cmd, func())
- func PatchExecutable(c *gc.C, patcher EnvironmentPatcher, execName, script string)
- func PatchExecutableAsEchoArgs(c *gc.C, patcher CleanupPatcher, execName string)
- type CleanupFunc
- type CleanupPatcher
- type CleanupSuite
- func (s *CleanupSuite) AddCleanup(cleanup CleanupFunc)
- func (s *CleanupSuite) AddSuiteCleanup(cleanup CleanupFunc)
- func (s *CleanupSuite) HookCommandOutput(outputFunc *func(cmd *exec.Cmd) ([]byte, error), output []byte, err error) <-chan *exec.Cmd
- func (s *CleanupSuite) PatchEnvPathPrepend(dir string)
- func (s *CleanupSuite) PatchEnvironment(name, value string)
- func (s *CleanupSuite) PatchValue(dest, value interface{})
- func (s *CleanupSuite) SetUpSuite(c *gc.C)
- func (s *CleanupSuite) SetUpTest(c *gc.C)
- func (s *CleanupSuite) TearDownSuite(c *gc.C)
- func (s *CleanupSuite) TearDownTest(c *gc.C)
- type EnvironmentPatcher
- type IsolationSuite
- type LoggingCleanupSuite
- type LoggingSuite
- type OsEnvSuite
- type Restorer
Constants ¶
const ( // EchoQuotedArgs is a simple bash script that prints out the // basename of the command followed by the args as quoted strings. EchoQuotedArgs = `#!/bin/bash --norc name=` + "`basename $0`" + ` argfile="$name.out" rm -f $argfile printf "%s" $name | tee -a $argfile for arg in "$@"; do printf " \"%s\"" "$arg" | tee -a $argfile done printf "\n" | tee -a $argfile ` )
Variables ¶
var HookChannelSize = 10
Functions ¶
func AssertEchoArgs ¶
AssertEchoArgs is used to check the args from an execution of a command that has been patchec using PatchExecutable containing EchoQuotedArgs.
func HookCommandOutput ¶
func HookCommandOutput( outputFunc *func(cmd *exec.Cmd) ([]byte, error), output []byte, err error) (<-chan *exec.Cmd, func())
HookCommandOutput intercepts CommandOutput to a function that passes the actual command and it's output back via a channel, and returns the error passed into this function. It also returns a cleanup function so you can restore the original function
func PatchExecutable ¶
func PatchExecutable(c *gc.C, patcher EnvironmentPatcher, execName, script string)
PatchExecutable creates an executable called 'execName' in a new test directory and that directory is added to the path.
func PatchExecutableAsEchoArgs ¶
func PatchExecutableAsEchoArgs(c *gc.C, patcher CleanupPatcher, execName string)
PatchExecutableAsEchoArgs creates an executable called 'execName' in a new test directory and that directory is added to the path. The content of the script is 'EchoQuotedArgs', and the args file is removed using a cleanup function.
Types ¶
type CleanupFunc ¶
type CleanupPatcher ¶
type CleanupPatcher interface { PatchEnvironment(name, value string) AddCleanup(cleanup CleanupFunc) }
type CleanupSuite ¶
type CleanupSuite struct {
// contains filtered or unexported fields
}
CleanupSuite adds the ability to add cleanup functions that are called during either test tear down or suite tear down depending on the method called.
func (*CleanupSuite) AddCleanup ¶
func (s *CleanupSuite) AddCleanup(cleanup CleanupFunc)
AddCleanup pushes the cleanup function onto the stack of functions to be called during TearDownTest.
func (*CleanupSuite) AddSuiteCleanup ¶
func (s *CleanupSuite) AddSuiteCleanup(cleanup CleanupFunc)
AddSuiteCleanup pushes the cleanup function onto the stack of functions to be called during TearDownSuite.
func (*CleanupSuite) HookCommandOutput ¶
func (s *CleanupSuite) HookCommandOutput( outputFunc *func(cmd *exec.Cmd) ([]byte, error), output []byte, err error, ) <-chan *exec.Cmd
HookCommandOutput calls the package function of the same name to mock out the result of a particular comand execution, and will call the restore function on test teardown.
func (*CleanupSuite) PatchEnvPathPrepend ¶
func (s *CleanupSuite) PatchEnvPathPrepend(dir string)
PatchEnvPathPrepend prepends the given path to the environment $PATH and restores the original path on test teardown.
func (*CleanupSuite) PatchEnvironment ¶
func (s *CleanupSuite) PatchEnvironment(name, value string)
PatchEnvironment sets the environment variable 'name' the the value passed in. The old value is saved and returned to the original value at test tear down time using a cleanup function.
func (*CleanupSuite) PatchValue ¶
func (s *CleanupSuite) PatchValue(dest, value interface{})
PatchValue sets the 'dest' variable the the value passed in. The old value is saved and returned to the original value at test tear down time using a cleanup function. The value must be assignable to the element type of the destination.
func (*CleanupSuite) SetUpSuite ¶
func (s *CleanupSuite) SetUpSuite(c *gc.C)
func (*CleanupSuite) SetUpTest ¶
func (s *CleanupSuite) SetUpTest(c *gc.C)
func (*CleanupSuite) TearDownSuite ¶
func (s *CleanupSuite) TearDownSuite(c *gc.C)
func (*CleanupSuite) TearDownTest ¶
func (s *CleanupSuite) TearDownTest(c *gc.C)
type EnvironmentPatcher ¶
type EnvironmentPatcher interface {
PatchEnvironment(name, value string)
}
EnvironmentPatcher is an interface that requires just one method: PatchEnvironment.
type IsolationSuite ¶
type IsolationSuite struct { OsEnvSuite CleanupSuite LoggingSuite }
IsolationSuite isolates the tests from the underlaying system environment, sets up test logging and exposes cleanup facilities.
func (*IsolationSuite) SetUpSuite ¶
func (s *IsolationSuite) SetUpSuite(c *gc.C)
func (*IsolationSuite) SetUpTest ¶
func (s *IsolationSuite) SetUpTest(c *gc.C)
func (*IsolationSuite) TearDownSuite ¶
func (s *IsolationSuite) TearDownSuite(c *gc.C)
func (*IsolationSuite) TearDownTest ¶
func (s *IsolationSuite) TearDownTest(c *gc.C)
type LoggingCleanupSuite ¶
type LoggingCleanupSuite struct { LoggingSuite CleanupSuite }
LoggingCleanupSuite is defined for backward compatibility. Do not use this suite in new tests.
func (*LoggingCleanupSuite) SetUpSuite ¶
func (s *LoggingCleanupSuite) SetUpSuite(c *gc.C)
func (*LoggingCleanupSuite) SetUpTest ¶
func (s *LoggingCleanupSuite) SetUpTest(c *gc.C)
func (*LoggingCleanupSuite) TearDownSuite ¶
func (s *LoggingCleanupSuite) TearDownSuite(c *gc.C)
func (*LoggingCleanupSuite) TearDownTest ¶
func (s *LoggingCleanupSuite) TearDownTest(c *gc.C)
type LoggingSuite ¶
type LoggingSuite struct{}
LoggingSuite redirects the juju logger to the test logger when embedded in a gocheck suite type.
func (*LoggingSuite) SetUpSuite ¶
func (s *LoggingSuite) SetUpSuite(c *gc.C)
func (*LoggingSuite) SetUpTest ¶
func (s *LoggingSuite) SetUpTest(c *gc.C)
func (*LoggingSuite) TearDownSuite ¶
func (s *LoggingSuite) TearDownSuite(c *gc.C)
func (*LoggingSuite) TearDownTest ¶
func (s *LoggingSuite) TearDownTest(c *gc.C)
type OsEnvSuite ¶
type OsEnvSuite struct {
// contains filtered or unexported fields
}
OsEnvSuite isolates the tests from the underlaying system environment. Environment variables are reset in SetUpTest and restored in TearDownTest.
func (*OsEnvSuite) SetUpSuite ¶
func (s *OsEnvSuite) SetUpSuite(c *gc.C)
func (*OsEnvSuite) SetUpTest ¶
func (s *OsEnvSuite) SetUpTest(c *gc.C)
func (*OsEnvSuite) TearDownSuite ¶
func (s *OsEnvSuite) TearDownSuite(c *gc.C)
func (*OsEnvSuite) TearDownTest ¶
func (s *OsEnvSuite) TearDownTest(c *gc.C)
type Restorer ¶
type Restorer func()
Restorer holds a function that can be used to restore some previous state.
func PatchEnvPathPrepend ¶
PatchEnvPathPrepend provides a simple way to prepend path to the start of the PATH environment variable. Returns a function that restores the environment to what it was before.
func PatchEnvironment ¶
PatchEnvironment provides a test a simple way to override a single environment variable. A function is returned that will return the environment to what it was before.
func PatchValue ¶
func PatchValue(dest, value interface{}) Restorer
PatchValue sets the value pointed to by the given destination to the given value, and returns a function to restore it to its original value. The value must be assignable to the element type of the destination.