juju: github.com/juju/juju/testing Index | Files | Directories

package testing

import "github.com/juju/juju/testing"

Index

Package Files

attrs.go base.go cert.go certs.go channel.go cmdblockhelper.go constants.go environ.go git.go imports.go mgo.go roundtripper.go shell.go targz.go time.go

Constants

const DefaultMongoPassword = "conn-from-name-secret"
const FakeAuthKeys = "" /* 182 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 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 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)

    ServerTLSCert, ServerCert, ServerKey = mustNewServer()

    Certs = serverCerts()

    // Other valid test certs different from the default.
    OtherCACert, OtherCAKey        = mustNewCA()
    OtherCACertX509, OtherCAKeyRSA = mustParseCertAndKey(OtherCACert, OtherCAKey)
)

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 ControllerTag = names.NewControllerTag("deadbeef-1bad-500d-9000-4b1d0d06f00d")

ControllerTag is a defined known valid UUID that can be used in testing.

var (
    // FakeSupportedJujuSeries is used to provide a series of canned results
    // of series to test bootstrap code against.
    FakeSupportedJujuSeries = set.NewStrings("precise", "trusty", "quantal", "bionic", series.DefaultSupportedLTS())
)
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,
}

TODO(katco): 2016-08-09: lp:1611427

var ModelTag = names.NewModelTag("deadbeef-0bad-400d-8000-4b1d0d06f00d")

ModelTag is a defined known valid UUID that can be used in testing.

func AssertOperationWasBlocked Uses

func AssertOperationWasBlocked(c *gc.C, err error, msg string)

func CheckString Uses

func CheckString(c *gc.C, value, expected string)

CheckString compares two strings. If they do not match then the spot where they do not match is logged.

func CheckWriteFileCommand Uses

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 CustomModelConfig Uses

func CustomModelConfig(c *gc.C, extra Attrs) *config.Config

CustomModelConfig returns an environment configuration with additional specified keys added.

func DumpTestLogsAfter Uses

func DumpTestLogsAfter(timeout time.Duration, c *gc.C, cleaner TestCleanup)

DumpTestLogsAfter will write the test logs to stdout if the timeout is reached.

func FakeControllerConfig Uses

func FakeControllerConfig() controller.Config

FakeControllerConfig() returns an environment configuration that is expected to be found in state for a fake controller.

func FindJujuCoreImports Uses

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 "github.com/juju/juju/" leaving just the short names.

func GetExportedFields Uses

func GetExportedFields(arg interface{}) set.Strings

GetExportedFields return the exported fields of a struct.

func MgoSSLTestPackage Uses

func MgoSSLTestPackage(t *testing.T)

MgoSSLTestPackage should be called to register the tests for any package that requires a secure (SSL) connection to a MongoDB server.

func MgoTestPackage Uses

func MgoTestPackage(t *testing.T)

MgoTestPackage should be called to register the tests for any package that requires a connection to a MongoDB server.

The server will be configured without SSL enabled, which slows down tests. For tests that care about security (which should be few), use MgoSSLTestPackage.

func ModelConfig Uses

func ModelConfig(c *gc.C) *config.Config

ModelConfig returns a default environment configuration suitable for setting in the state.

func NewCA Uses

func NewCA(commonName, UUID string, expiry time.Time) (certPEM, keyPEM string, err error)

NewCA returns a random one of the pre-generated certs to speed up tests. The comment on the certs are not going to match the args.

func NonZeroTime Uses

func NonZeroTime() time.Time

NonZeroTime can be used in tests instead of time.Now() when the returned time.Time value must be non-zero (its IsZero() method returns false).

func SkipFlaky Uses

func SkipFlaky(c *gc.C, bugID string)

SkipFlaky skips the test if there is an open bug for intermittent test failures

func SkipIfI386 Uses

func SkipIfI386(c *gc.C, bugID string)

SkipIfI386 skips the test if the arch is I386.

func SkipIfPPC64EL Uses

func SkipIfPPC64EL(c *gc.C, bugID string)

SkipIfPPC64EL skips the test if the arch is PPC64EL and the compiler is gccgo.

func SkipIfS390X Uses

func SkipIfS390X(c *gc.C, bugID string)

SkipIfS390X skips the test if the arch is S390X.

func SkipIfWindowsBug Uses

func SkipIfWindowsBug(c *gc.C, bugID string)

SkipIfWindowsBug skips the test if the OS is Windows.

func SkipUnlessControllerOS Uses

func SkipUnlessControllerOS(c *gc.C)

SkipUnlessControllerOS skips the test if the current OS is not a supported controller OS.

func TarGz Uses

func TarGz(files ...*TarFile) ([]byte, string)

TarGz returns the given files in gzipped tar-archive format, along with the sha256 checksum.

func ZeroTime Uses

func ZeroTime() time.Time

ZeroTime can be used in tests instead of time.Now() when the returned time.Time value is not relevant.

Example: instead of now := time.Now() use now := testing.ZeroTime().

type Attrs Uses

type Attrs map[string]interface{}

Attrs is a convenience type for messing around with configuration attributes.

func FakeConfig Uses

func FakeConfig() Attrs

FakeConfig() returns an environment configuration for a fake provider with all required attributes set.

func (Attrs) Delete Uses

func (a Attrs) Delete(attrNames ...string) Attrs

func (Attrs) Merge Uses

func (a Attrs) Merge(with Attrs) Attrs

type BaseSuite Uses

type BaseSuite struct {
    testing.CleanupSuite
    testing.LoggingSuite
    JujuOSEnvSuite
    InitialLoggingConfig string
    // contains filtered or unexported fields
}

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 Uses

func (s *BaseSuite) SetUpSuite(c *gc.C)

func (*BaseSuite) SetUpTest Uses

func (s *BaseSuite) SetUpTest(c *gc.C)

func (*BaseSuite) TearDownSuite Uses

func (s *BaseSuite) TearDownSuite(c *gc.C)

func (*BaseSuite) TearDownTest Uses

func (s *BaseSuite) TearDownTest(c *gc.C)

type CannedRoundTripper Uses

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 Uses

func NewCannedRoundTripper(files map[string]string, errorURLs map[string]int) *CannedRoundTripper

NewCannedRoundTripper returns a CannedRoundTripper with the given canned responses.

func (*CannedRoundTripper) RoundTrip Uses

func (v *CannedRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip returns a canned error or body for the given request.

type CmdBlockHelper Uses

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

CmdBlockHelper is a helper struct used to block commands.

func NewCmdBlockHelper Uses

func NewCmdBlockHelper(api base.APICallCloser) CmdBlockHelper

NewCmdBlockHelper creates a block switch used in testing to manage desired juju blocks.

func (*CmdBlockHelper) AssertBlocked Uses

func (s *CmdBlockHelper) AssertBlocked(c *gc.C, err error, msg string)

AssertBlocked is going to be removed as soon as all cmd tests mock out API. the corect method to call will become AssertOperationWasBlocked.

func (*CmdBlockHelper) BlockAllChanges Uses

func (s *CmdBlockHelper) BlockAllChanges(c *gc.C, msg string)

BlockAllChanges switches changes block on. This prevents all changes to juju environment.

func (*CmdBlockHelper) BlockDestroyModel Uses

func (s *CmdBlockHelper) BlockDestroyModel(c *gc.C, msg string)

BlockDestroyModel switches destroy block on. This prevents juju environment destruction.

func (*CmdBlockHelper) BlockRemoveObject Uses

func (s *CmdBlockHelper) BlockRemoveObject(c *gc.C, msg string)

BlockRemoveObject switches remove block on. This prevents any object/entity removal on juju environment

func (*CmdBlockHelper) Close Uses

func (s *CmdBlockHelper) Close()

type ContentAsserterC Uses

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 Uses

func (a *ContentAsserterC) AssertClosed()

AssertClosed ensures that we get a closed event on the channel

func (*ContentAsserterC) AssertNoReceive Uses

func (a *ContentAsserterC) AssertNoReceive()

Assert that we fail to receive on the channel after a short wait.

func (*ContentAsserterC) AssertOneReceive Uses

func (a *ContentAsserterC) AssertOneReceive() interface{}

AssertOneReceive checks that we have exactly one message, and no more

func (*ContentAsserterC) AssertOneValue Uses

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 Uses

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 Uses

type FakeJujuXDGDataHomeSuite struct {
    JujuOSEnvSuite
    gitjujutesting.FakeHomeSuite
}

FakeJujuXDGDataHomeSuite isolates the user's home directory and sets up a Juju home with a sample environment and certificate.

func (*FakeJujuXDGDataHomeSuite) AssertConfigParameterUpdated Uses

func (s *FakeJujuXDGDataHomeSuite) AssertConfigParameterUpdated(c *gc.C, key, value string)

AssertConfigParameterUpdated updates environment parameter and asserts that no errors were encountered.

func (*FakeJujuXDGDataHomeSuite) SetUpTest Uses

func (s *FakeJujuXDGDataHomeSuite) SetUpTest(c *gc.C)

func (*FakeJujuXDGDataHomeSuite) TearDownTest Uses

func (s *FakeJujuXDGDataHomeSuite) TearDownTest(c *gc.C)

type GitSuite Uses

type GitSuite struct {
    BaseSuite
}

func (*GitSuite) SetUpTest Uses

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

type JujuOSEnvSuite Uses

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 Uses

func (s *JujuOSEnvSuite) SetFeatureFlags(flag ...string)

func (*JujuOSEnvSuite) SetInitialFeatureFlags Uses

func (s *JujuOSEnvSuite) SetInitialFeatureFlags(flags ...string)

SetInitialFeatureFlags sets the feature flags to be in effect for the next call to SetUpTest.

func (*JujuOSEnvSuite) SetModelAndController Uses

func (s *JujuOSEnvSuite) SetModelAndController(c *gc.C, controllerName, modelName string)

SetModelAndController adds a controller, and a model in that controller, and sets the controller as the current controller, and the model as the current model.

func (*JujuOSEnvSuite) SetUpTest Uses

func (s *JujuOSEnvSuite) SetUpTest(c *gc.C)

func (*JujuOSEnvSuite) TearDownTest Uses

func (s *JujuOSEnvSuite) TearDownTest(c *gc.C)

type NotifyAsserterC Uses

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 Uses

func (a *NotifyAsserterC) AssertClosed()

AssertClosed ensures that we get a closed event on the channel

func (*NotifyAsserterC) AssertNoReceive Uses

func (a *NotifyAsserterC) AssertNoReceive()

Assert that we fail to receive on the channel after a short wait.

func (*NotifyAsserterC) AssertOneReceive Uses

func (a *NotifyAsserterC) AssertOneReceive()

AssertOneReceive checks that we have exactly one message, and no more

func (*NotifyAsserterC) AssertReceive Uses

func (a *NotifyAsserterC) AssertReceive()

AssertReceive will ensure that we get an event on the channel and the channel is not closed.

type PackageManagerStruct Uses

type PackageManagerStruct struct {
    PackageManager    string
    RepositoryManager string
    PackageQuery      string
}

func GetPackageManager Uses

func GetPackageManager() (s PackageManagerStruct, err error)

type ProxyRoundTripper Uses

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 Uses

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).

func (*ProxyRoundTripper) RoundTrip Uses

func (prt *ProxyRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

type TarFile Uses

type TarFile struct {
    Header   tar.Header
    Contents string
}

TarFile represents a file to be archived.

func NewTarFile Uses

func NewTarFile(name string, mode os.FileMode, contents string) *TarFile

NewTarFile returns a new TarFile instance with the given file mode and contents.

type TestCleanup Uses

type TestCleanup interface {
    AddCleanup(func(*gc.C))
}

TestCleanup is used to allow DumpTestLogsAfter to take any test suite that supports the standard cleanup function.

Directories

PathSynopsis
factory

Package testing imports 42 packages (graph) and is imported by 654 packages. Updated 2019-10-07. Refresh now. Tools for package owners.