Documentation ¶
Index ¶
- Constants
- Variables
- func CheckString(c *gc.C, value, expected string)
- func CheckWriteFileCommand(c *gc.C, cmd, filename, expected string, ...)
- func Context(c *gc.C) *cmd.Context
- func ContextForDir(c *gc.C, dir string) *cmd.Context
- func CustomModelConfig(c *gc.C, extra Attrs) *config.Config
- func DumpTestLogsAfter(timeout time.Duration, c *gc.C, cleaner TestCleanup)
- func ExtractCommandsFromHelpOutput(ctx *cmd.Context) []string
- func FindJujuCoreImports(c *gc.C, packageName string) []string
- func InitCommand(c cmd.Command, args []string) error
- func MgoTestPackage(t *testing.T)
- func ModelConfig(c *gc.C) *config.Config
- func NewFlagSet() *gnuflag.FlagSet
- func RunCommand(c *gc.C, com cmd.Command, args ...string) (*cmd.Context, error)
- func RunCommandInDir(c *gc.C, com cmd.Command, args []string, dir string) (*cmd.Context, error)
- func SkipIfGitNotAvailable(c *gc.C)
- func SkipIfI386(c *gc.C, bugID string)
- func SkipIfPPC64EL(c *gc.C, bugID string)
- func SkipIfWindowsBug(c *gc.C, bugID string)
- func Stderr(ctx *cmd.Context) string
- func Stdout(ctx *cmd.Context) string
- func TarGz(files ...*TarFile) ([]byte, string)
- func TestInit(c *gc.C, com cmd.Command, args []string, errPat string)
- func TestLockingFunction(lock *sync.Mutex, function func())
- type Attrs
- type BaseSuite
- type CannedRoundTripper
- type Clock
- type ContentAsserterC
- type FakeJujuXDGDataHomeSuite
- type GitSuite
- type JujuOSEnvSuite
- type NotifyAsserterC
- type PackageManagerStruct
- type ProxyRoundTripper
- type StubClock
- type TarFile
- type TestCleanup
- type Timer
Constants ¶
const DefaultMongoPassword = "conn-from-name-secret"
const FakeAuthKeys = `` /* 180-byte string literal not displayed */
FakeAuthKeys holds the authorized key used for testing purposes in FakeConfig. It is valid for parsing with the utils/ssh authorized-key utilities.
const FakeDefaultSeries = "trusty"
const LongWait = 10 * time.Second
LongWait is used when something should have already happened, or happens quickly, but we want to make sure we just haven't missed it. As in, the test suite should proceed without sleeping at all, but just in case. It is long so that we don't have spurious failures without actually slowing down the test suite
const (
SampleModelName = "erewhemos"
)
const ShortWait = 50 * time.Millisecond
ShortWait is a reasonable amount of time to block waiting for something that shouldn't actually happen. (as in, the test suite will *actually* wait this long before continuing)
Variables ¶
var (
CACert, CAKey = mustNewCA()
CACertX509, CAKeyRSA = mustParseCertAndKey(CACert, CAKey)
ServerCert, ServerKey = mustNewServer()
Certs = serverCerts()
// Other valid test certs different from the default.
OtherCACert, OtherCAKey = mustNewCA()
)
CACert and CAKey make up a CA key pair. CACertX509 and CAKeyRSA hold their parsed equivalents. ServerCert and ServerKey hold a CA-signed server cert/key. Certs holds the certificates and keys required to make a secure connection to a Mongo database.
var FakeVersionNumber = version.MustParse("1.99.0")
FakeVersionNumber is a valid version number that can be used in testing.
var LongAttempt = &utils.AttemptStrategy{ Total: LongWait, Delay: ShortWait, }
var ModelTag = names.NewModelTag("deadbeef-0bad-400d-8000-4b1d0d06f00d")
ModelTag is a defined known valid UUID that can be used in testing.
Functions ¶
func CheckString ¶
CheckString compares two strings. If they do not match then the spot where they do not match is logged.
func CheckWriteFileCommand ¶
func CheckWriteFileCommand(c *gc.C, cmd, filename, expected string, parse func(lines []string) interface{})
CheckWriteFileCommand verifies that the given shell command correctly writes the expected content to the given filename. The provided parse function decomposes file content into structured data that may be correctly compared regardless of ordering within the content. If parse is nil then the content lines are used un-parsed.
func Context ¶
Context creates a simple command execution context with the current dir set to a newly created directory within the test directory.
func ContextForDir ¶
ContextForDir creates a simple command execution context with the current dir set to the specified directory.
func CustomModelConfig ¶
CustomModelConfig returns an environment configuration with additional specified keys added.
func DumpTestLogsAfter ¶
func DumpTestLogsAfter(timeout time.Duration, c *gc.C, cleaner TestCleanup)
DumpTestLogsAfter will write the test logs to stdout if the timeout is reached.
func ExtractCommandsFromHelpOutput ¶
ExtractCommandsFromHelpOutput takes the standard output from the command context and looks for the "commands:" string and returns the commands output after that.
func FindJujuCoreImports ¶
FindJujuCoreImports returns a sorted list of juju-core packages that are imported by the packageName parameter. The resulting list removes the common prefix "github.com/juju/juju/" leaving just the short names.
func InitCommand ¶
InitCommand will create a new flag set, and call the Command's SetFlags and Init methods with the appropriate args.
func MgoTestPackage ¶
MgoTestPackage should be called to register the tests for any package that requires a secure connection to a MongoDB server.
func ModelConfig ¶
ModelConfig returns a default environment configuration suitable for setting in the state.
func NewFlagSet ¶
NewFlagSet creates a new flag set using the standard options, particularly the option to stop the gnuflag methods from writing to StdErr or StdOut.
func RunCommand ¶
RunCommand runs a command with the specified args. The returned error may come from either the parsing of the args, the command initialisation, or the actual running of the command. Access to the resulting output streams is provided through the returned context instance.
func RunCommandInDir ¶
RunCommandInDir works like RunCommand, but runs with a context that uses dir.
func SkipIfGitNotAvailable ¶
func SkipIfI386 ¶
SkipIfI386 skips the test if the arch is I386.
func SkipIfPPC64EL ¶
SkipIfPPC64EL skips the test if the arch is PPC64EL and the compiler is gccgo.
func SkipIfWindowsBug ¶
SkipIfWindowsBug skips the test if the OS is Windows.
func Stderr ¶
Stderr takes a command Context that we assume has been created in this package, and gets the content of the Stderr buffer as a string.
func Stdout ¶
Stdout takes a command Context that we assume has been created in this package, and gets the content of the Stdout buffer as a string.
func TarGz ¶
TarGz returns the given files in gzipped tar-archive format, along with the sha256 checksum.
func TestInit ¶
TestInit checks that a command initialises correctly with the given set of arguments.
func TestLockingFunction ¶
TestLockingFunction verifies that a function obeys a given lock.
Use this as a building block in your own tests for proper locking. Parameters are a lock that you expect your function to block on, and the function that you want to test for proper locking on that lock.
This helper attempts to verify that the function both obtains and releases the lock. It will panic if the function fails to do either. TODO: Support generic sync.Locker instead of just Mutex. TODO: This could be a gocheck checker. TODO(rog): make this work reliably even for functions that take longer than a few µs to execute.
Types ¶
type Attrs ¶
type Attrs map[string]interface{}
Attrs is a convenience type for messing around with configuration attributes.
func FakeConfig ¶
func FakeConfig() Attrs
FakeConfig() returns an environment configuration for a fake provider with all required attributes set.
type BaseSuite ¶
type BaseSuite struct { testing.CleanupSuite testing.LoggingSuite JujuOSEnvSuite }
BaseSuite provides required functionality for all test suites when embedded in a gocheck suite type: - logger redirect - no outgoing network access - protection of user's home directory - scrubbing of env vars TODO (frankban) 2014-06-09: switch to using IsolationSuite. NOTE: there will be many tests that fail when you try to change to the IsolationSuite that rely on external things in PATH.
func (*BaseSuite) SetUpSuite ¶
func (*BaseSuite) TearDownSuite ¶
func (*BaseSuite) TearDownTest ¶
type CannedRoundTripper ¶
type CannedRoundTripper struct {
// contains filtered or unexported fields
}
CannedRoundTripper can be used to provide canned "http" responses without actually starting an HTTP server.
Use this in conjunction with ProxyRoundTripper. A ProxyRoundTripper is what gets registered as the default handler for a given protocol (such as "test") and then tests can direct the ProxyRoundTripper to delegate to a CannedRoundTripper. The reason for this is that we can register a roundtripper to handle a scheme, but there is no way to unregister it: you may need to re-use the same ProxyRoundTripper but use different CannedRoundTrippers to return different results.
func NewCannedRoundTripper ¶
func NewCannedRoundTripper(files map[string]string, errorURLs map[string]int) *CannedRoundTripper
NewCannedRoundTripper returns a CannedRoundTripper with the given canned responses.
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock implements a mock clock.Clock for testing purposes.
func NewClock ¶
NewClock returns a new clock set to the supplied time. If your SUT needs to call After, AfterFunc, or Timer.Reset more than 1024 times: (1) you have probably written a bad test; and (2) you'll need to read from the Alarms chan to keep the buffer clear.
func (*Clock) Advance ¶
Advance advances the result of Now by the supplied duration, and sends the "current" time on all alarms which are no longer "in the future".
func (*Clock) Alarms ¶
func (clock *Clock) Alarms() <-chan struct{}
Alarms returns a channel on which you can read one value for every call to After and AfterFunc; and for every successful Timer.Reset backed by this Clock. It might not be elegant but it's necessary when testing time logic that runs on a goroutine other than that of the test.
type ContentAsserterC ¶
type ContentAsserterC struct { // C is a gocheck C structure for doing assertions C *gc.C // Chan is the channel we want to receive on Chan interface{} // Precond will be called before waiting on the channel, can be nil Precond func() }
ContentAsserterC is like NotifyAsserterC in that it checks the behavior of a channel. The difference is that we expect actual content on the channel, so callers need to put that into and out of an 'interface{}'
func (*ContentAsserterC) AssertClosed ¶
func (a *ContentAsserterC) AssertClosed()
AssertClosed ensures that we get a closed event on the channel
func (*ContentAsserterC) AssertNoReceive ¶
func (a *ContentAsserterC) AssertNoReceive()
Assert that we fail to receive on the channel after a short wait.
func (*ContentAsserterC) AssertOneReceive ¶
func (a *ContentAsserterC) AssertOneReceive() interface{}
AssertOneReceive checks that we have exactly one message, and no more
func (*ContentAsserterC) AssertOneValue ¶
func (a *ContentAsserterC) AssertOneValue(val interface{}) interface{}
AssertOneValue checks that exactly 1 message was sent, and that the content DeepEquals the value. It also returns the value in case further inspection is desired.
func (*ContentAsserterC) AssertReceive ¶
func (a *ContentAsserterC) AssertReceive() interface{}
AssertReceive will ensure that we get an event on the channel and the channel is not closed. It will return the content received
type FakeJujuXDGDataHomeSuite ¶
type FakeJujuXDGDataHomeSuite struct { JujuOSEnvSuite gitjujutesting.FakeHomeSuite // contains filtered or unexported fields }
FakeJujuXDGDataHomeSuite isolates the user's home directory and sets up a Juju home with a sample environment and certificate.
func (*FakeJujuXDGDataHomeSuite) AssertConfigParameterUpdated ¶
func (s *FakeJujuXDGDataHomeSuite) AssertConfigParameterUpdated(c *gc.C, key, value string)
AssertConfigParameterUpdated updates environment parameter and asserts that no errors were encountered.
func (*FakeJujuXDGDataHomeSuite) SetUpTest ¶
func (s *FakeJujuXDGDataHomeSuite) SetUpTest(c *gc.C)
func (*FakeJujuXDGDataHomeSuite) TearDownTest ¶
func (s *FakeJujuXDGDataHomeSuite) TearDownTest(c *gc.C)
type JujuOSEnvSuite ¶
type JujuOSEnvSuite struct {
// contains filtered or unexported fields
}
JujuOSEnvSuite isolates the tests from Juju environment variables. This is intended to be only used by existing suites, usually embedded in BaseSuite and in FakeJujuXDGDataHomeSuite. Eventually the tests relying on JujuOSEnvSuite will be converted to use the IsolationSuite in github.com/juju/testing, and this suite will be removed. Do not use JujuOSEnvSuite when writing new tests.
func (*JujuOSEnvSuite) SetFeatureFlags ¶
func (s *JujuOSEnvSuite) SetFeatureFlags(flag ...string)
func (*JujuOSEnvSuite) SetInitialFeatureFlags ¶
func (s *JujuOSEnvSuite) SetInitialFeatureFlags(flags ...string)
SetInitialFeatureFlags sets the feature flags to be in effect for the next call to SetUpTest.
func (*JujuOSEnvSuite) SetUpTest ¶
func (s *JujuOSEnvSuite) SetUpTest(c *gc.C)
func (*JujuOSEnvSuite) TearDownTest ¶
func (s *JujuOSEnvSuite) TearDownTest(c *gc.C)
type NotifyAsserterC ¶
type NotifyAsserterC struct { // C is a gocheck C structure for doing assertions C *gc.C // Chan is the channel we want to receive on Chan <-chan struct{} // Precond will be called before waiting on the channel, can be nil Precond func() }
NotifyAsserterC gives helper functions for making assertions about how a channel operates (whether we get a receive event or not, whether it is closed, etc.)
func (*NotifyAsserterC) AssertClosed ¶
func (a *NotifyAsserterC) AssertClosed()
AssertClosed ensures that we get a closed event on the channel
func (*NotifyAsserterC) AssertNoReceive ¶
func (a *NotifyAsserterC) AssertNoReceive()
Assert that we fail to receive on the channel after a short wait.
func (*NotifyAsserterC) AssertOneReceive ¶
func (a *NotifyAsserterC) AssertOneReceive()
AssertOneReceive checks that we have exactly one message, and no more
func (*NotifyAsserterC) AssertReceive ¶
func (a *NotifyAsserterC) AssertReceive()
AssertReceive will ensure that we get an event on the channel and the channel is not closed.
type PackageManagerStruct ¶
type PackageManagerStruct struct { PackageManager string RepositoryManager string PackageQuery string }
func GetPackageManager ¶
func GetPackageManager() (s PackageManagerStruct, err error)
type ProxyRoundTripper ¶
type ProxyRoundTripper struct { // Sub is the roundtripper that this roundtripper delegates to, if any. // If you leave this nil, this roundtripper is effectively disabled. Sub http.RoundTripper }
ProxyRoundTripper is an http.RoundTripper implementation that does nothing but delegate to another RoundTripper. This lets tests change how they handle requests for a given scheme, despite the fact that the standard library does not support un-registration, or registration of a new roundtripper with a URL scheme that's already handled.
Use the RegisterForScheme method to install this as the standard handler for a particular protocol. For example, if you call prt.RegisterForScheme("test") then afterwards, any request to "test:///foo" will be routed to prt.
func (*ProxyRoundTripper) RegisterForScheme ¶
func (prt *ProxyRoundTripper) RegisterForScheme(scheme string)
RegisterForScheme registers a ProxyRoundTripper as the default roundtripper for the given URL scheme.
This cannot be undone, nor overwritten with a different roundtripper. If you change your mind later about what the roundtripper should do, set its "Sub" field to delegate to a different roundtripper (or to nil if you don't want to handle its requests at all any more).
type StubClock ¶
type StubClock struct { *testing.Stub ReturnNow time.Time ReturnAfter <-chan time.Time ReturnAfterFunc clock.Timer }
func NewStubClock ¶
type TestCleanup ¶
TestCleanup is used to allow DumpTestLogsAfter to take any test suite that supports the standard cleanup function.