testbase

package
v0.0.0-...-a7271ac Latest Latest
Warning

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

Go to latest
Published: May 4, 2014 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindJujuCoreImports

func FindJujuCoreImports(c *gc.C, packageName string) []string

FindJujuCoreImports returns a sorted list of juju-core packages that are imported by the packageName parameter. The resulting list removes the common prefix "launchpad.net/juju-core/" leaving just the short names.

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

Types

type CleanupFunc

type CleanupFunc func(*gc.C)

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 LoggingSuite

type LoggingSuite struct {
	CleanupSuite
}

LoggingSuite redirects the juju logger to the test logger when embedded in a gocheck suite type.

func (*LoggingSuite) SetUpSuite

func (t *LoggingSuite) SetUpSuite(c *gc.C)

func (*LoggingSuite) SetUpTest

func (t *LoggingSuite) SetUpTest(c *gc.C)

type Restorer

type Restorer func()

Restorer holds a function that can be used to restore some previous state.

func PatchEnvPathPrepend

func PatchEnvPathPrepend(dir string) Restorer

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

func PatchEnvironment(name, value string) Restorer

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.

func (Restorer) Add

func (f Restorer) Add(f1 Restorer) Restorer

Add returns a Restorer that restores first f1 and then f. It is valid to call this on a nil Restorer.

func (Restorer) Restore

func (r Restorer) Restore()

Restore restores some previous state.

Jump to

Keyboard shortcuts

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