juju-core: github.com/trobert2/juju-core/testing Index | Files | Directories

package testing

import "github.com/trobert2/juju-core/testing"

Index

Package Files

attrs.go cert.go channel.go charm.go cmd.go constants.go environ.go git.go http.go locking.go mgo.go targz.go

Constants

const (
    SampleEnvName = "erewhemos"
    EnvDefault    = "default:\n  " + SampleEnvName + "\n"
)
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 MultipleEnvConfig = EnvDefault + MultipleEnvConfigNoDefault
const MultipleEnvConfigNoDefault = "" /* 137 byte string literal not displayed */+
    DefaultMongoPassword + `
    erewhemos-2:
        type: dummy
        state-server: true
        authorized-keys: i-am-a-key
        admin-secret: ` + DefaultMongoPassword + `
`
const SampleCertName = "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)

const SingleEnvConfig = EnvDefault + SingleEnvConfigNoDefault
const SingleEnvConfigNoDefault = "" /* 137 byte string literal not displayed */+
    DefaultMongoPassword + `
`

Environment names below are explicit as it makes them more readable.

Variables

var (
    CACert, CAKey = mustNewCA()

    CACertX509, CAKeyRSA = mustParseCertAndKey([]byte(CACert), []byte(CAKey))

    ServerCert, ServerKey = mustNewServer()
)

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.

var Charms = &Repo{}

Charms represents the specific charm repository stored in this package and used by the Juju unit tests. The series name is "quantal".

var LongAttempt = &utils.AttemptStrategy{
    Total: LongWait,
    Delay: ShortWait,
}
var (
    // MgoServer is a shared mongo server used by tests.
    MgoServer = &MgoInstance{ssl: true}
)
var Server = NewHTTPServer(5 * time.Second)
var SupportedSeries = []string{"precise", "quantal", "raring", "saucy", "trusty"}

SupportedSeries lists the series known to Juju.

func Context Uses

func Context(c *gc.C) *cmd.Context

Context creates a simple command execution context with the current dir set to a newly created directory within the test directory.

func ContextForDir Uses

func ContextForDir(c *gc.C, dir string) *cmd.Context

ContextForDir creates a simple command execution context with the current dir set to the specified directory.

func CustomEnvironConfig Uses

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

CustomEnvironConfig returns an environment configuration with additional specified keys added.

func EnvironConfig Uses

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

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

func FindTCPPort Uses

func FindTCPPort() int

FindTCPPort finds an unused TCP port and returns it. Use of this function has an inherent race condition - another process may claim the port before we try to use it. We hope that the probability is small enough during testing to be negligible.

func HomePath Uses

func HomePath(names ...string) string

func InitCommand Uses

func InitCommand(c cmd.Command, args []string) error

InitCommand will create a new flag set, and call the Command's SetFlags and Init methods with the appropriate args.

func MgoTestPackage Uses

func MgoTestPackage(t *stdtesting.T)

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

func MgoTestPackageSsl Uses

func MgoTestPackageSsl(t *stdtesting.T, ssl bool)

func NewFlagSet Uses

func NewFlagSet() *gnuflag.FlagSet

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 Uses

func RunCommand(c *gc.C, com cmd.Command, args []string) (*cmd.Context, error)

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 Uses

func RunCommandInDir(c *gc.C, com cmd.Command, args []string, dir string) (*cmd.Context, error)

RunCommandInDir works like RunCommand, but runs with a context that uses dir.

func Stderr Uses

func Stderr(ctx *cmd.Context) string

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 Uses

func Stdout(ctx *cmd.Context) string

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 Uses

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

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

func TestInit Uses

func TestInit(c *gc.C, com cmd.Command, args []string, errPat string)

TestInit checks that a command initialises correctly with the given set of arguments.

func TestLockingFunction Uses

func TestLockingFunction(lock *sync.Mutex, function func())

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.

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 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) 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 FakeHome Uses

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

func MakeEmptyFakeHome Uses

func MakeEmptyFakeHome(c *gc.C) *FakeHome

func MakeEmptyFakeHomeWithoutJuju Uses

func MakeEmptyFakeHomeWithoutJuju(c *gc.C) *FakeHome

func MakeFakeHome Uses

func MakeFakeHome(c *gc.C, envConfig string, certNames ...string) *FakeHome

MakeFakeHome creates a new temporary directory through the test checker, and overrides the HOME environment variable to point to this new temporary directory.

A new ~/.juju/environments.yaml file is created with the content of the `envConfig` parameter, and CAKeys are written for each of the 'certNames' specified.

func MakeFakeHomeNoEnvironments Uses

func MakeFakeHomeNoEnvironments(c *gc.C, certNames ...string) *FakeHome

MakeFakeHomeNoEnvironments creates a new temporary directory through the test checker, and overrides the HOME environment variable to point to this new temporary directory.

No ~/.juju/environments.yaml exists, but CAKeys are written for each of the 'certNames' specified, and the id_rsa.pub file is written to to the .ssh dir.

func MakeFakeHomeWithFiles Uses

func MakeFakeHomeWithFiles(c *gc.C, files []TestFile) *FakeHome

func MakeMultipleEnvHome Uses

func MakeMultipleEnvHome(c *gc.C) *FakeHome

func MakeSampleHome Uses

func MakeSampleHome(c *gc.C) *FakeHome

func (*FakeHome) AddFiles Uses

func (h *FakeHome) AddFiles(c *gc.C, files []TestFile)

func (*FakeHome) FileContents Uses

func (h *FakeHome) FileContents(c *gc.C, path string) string

FileContents returns the test file contents for the given specified path (which may be relative, so we compare with the base filename only).

func (*FakeHome) FileExists Uses

func (h *FakeHome) FileExists(path string) bool

FileExists returns if the given relative file path exists in the fake home.

func (*FakeHome) Restore Uses

func (h *FakeHome) Restore()

type FakeHomeSuite Uses

type FakeHomeSuite struct {
    testbase.LoggingSuite
    Home *FakeHome
}

func (*FakeHomeSuite) SetUpTest Uses

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

type GitSuite Uses

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

func (*GitSuite) SetUpTest Uses

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

func (*GitSuite) TearDownTest Uses

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

type HTTPServer Uses

type HTTPServer struct {
    URL     string
    Timeout time.Duration
    // contains filtered or unexported fields
}

func NewHTTPServer Uses

func NewHTTPServer(timeout time.Duration) *HTTPServer

func (*HTTPServer) Flush Uses

func (s *HTTPServer) Flush()

Flush discards all pending requests and responses.

func (*HTTPServer) Response Uses

func (s *HTTPServer) Response(status int, headers map[string]string, body []byte)

Response prepares the test server to respond the following request using the provided response parameters.

func (*HTTPServer) ResponseFunc Uses

func (s *HTTPServer) ResponseFunc(n int, f ResponseFunc)

ResponseFunc prepares the test server to respond the following n requests using f to build each response.

func (*HTTPServer) ResponseMap Uses

func (s *HTTPServer) ResponseMap(n int, m ResponseMap)

ResponseMap prepares the test server to respond the following n requests using the m to obtain the responses.

func (*HTTPServer) Responses Uses

func (s *HTTPServer) Responses(n int, status int, headers map[string]string, body []byte)

Responses prepares the test server to respond the following n requests using the provided response parameters.

func (*HTTPServer) ServeHTTP Uses

func (s *HTTPServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*HTTPServer) Start Uses

func (s *HTTPServer) Start()

func (*HTTPServer) WaitRequest Uses

func (s *HTTPServer) WaitRequest() *http.Request

WaitRequest returns the next request made to the http server from the queue. If no requests were previously made, it waits until the timeout value for one to be made.

func (*HTTPServer) WaitRequests Uses

func (s *HTTPServer) WaitRequests(n int) []*http.Request

WaitRequests returns the next n requests made to the http server from the queue. If not enough requests were previously made, it waits until the timeout value for them to be made.

type HTTPSuite Uses

type HTTPSuite struct{}

func (*HTTPSuite) SetUpSuite Uses

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

func (*HTTPSuite) SetUpTest Uses

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

func (*HTTPSuite) TearDownSuite Uses

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

func (*HTTPSuite) TearDownTest Uses

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

func (*HTTPSuite) URL Uses

func (s *HTTPSuite) URL(path string) string

type MgoInstance Uses

type MgoInstance struct {

    // Params is a list of additional parameters that will be passed to
    // the mongod application
    Params []string
    // contains filtered or unexported fields
}

func (*MgoInstance) Addr Uses

func (m *MgoInstance) Addr() string

Addr returns the address of the MongoDB server.

func (*MgoInstance) Destroy Uses

func (inst *MgoInstance) Destroy()

func (*MgoInstance) Dial Uses

func (inst *MgoInstance) Dial() (*mgo.Session, error)

Dial returns a new connection to the MongoDB server.

func (*MgoInstance) DialDirect Uses

func (inst *MgoInstance) DialDirect() (*mgo.Session, error)

DialDirect returns a new direct connection to the shared MongoDB server. This must be used if you're connecting to a replicaset that hasn't been initiated yet.

func (*MgoInstance) MustDial Uses

func (inst *MgoInstance) MustDial() *mgo.Session

MustDial returns a new connection to the MongoDB server, and panics on errors.

func (*MgoInstance) MustDialDirect Uses

func (inst *MgoInstance) MustDialDirect() *mgo.Session

MustDialDirect works like DialDirect, but panics on errors.

func (*MgoInstance) Port Uses

func (m *MgoInstance) Port() int

Port returns the port of the MongoDB server.

func (*MgoInstance) Reset Uses

func (inst *MgoInstance) Reset()

Reset deletes all content from the MongoDB server and panics if it encounters errors.

func (*MgoInstance) Restart Uses

func (inst *MgoInstance) Restart()

Restart restarts the mongo server, useful for testing what happens when a state server goes down.

func (*MgoInstance) Start Uses

func (inst *MgoInstance) Start(ssl bool) error

Start starts a MongoDB server in a temporary directory.

type MgoSuite Uses

type MgoSuite struct {
    Session *mgo.Session
}

MgoSuite is a suite that deletes all content from the shared MongoDB server at the end of every test and supplies a connection to the shared MongoDB server.

func (*MgoSuite) SetUpSuite Uses

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

func (*MgoSuite) SetUpTest Uses

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

func (*MgoSuite) TearDownSuite Uses

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

func (*MgoSuite) TearDownTest Uses

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

type MockCharmStore Uses

type MockCharmStore struct {
    AuthAttrs string
    TestMode  bool
    // contains filtered or unexported fields
}

MockCharmStore implements charm.Repository and is used to isolate tests that would otherwise need to hit the real charm store.

func NewMockCharmStore Uses

func NewMockCharmStore() *MockCharmStore

func (*MockCharmStore) Get Uses

func (s *MockCharmStore) Get(charmURL *charm.URL) (charm.Charm, error)

Get implements charm.Repository.Get.

func (*MockCharmStore) Latest Uses

func (s *MockCharmStore) Latest(charmURLs ...*charm.URL) ([]charm.CharmRevision, error)

Latest implements charm.Repository.Latest.

func (*MockCharmStore) SetCharm Uses

func (s *MockCharmStore) SetCharm(charmURL *charm.URL, bundle *charm.Bundle) error

SetCharm adds and removes charms in s. The affected charm is identified by charmURL, which must be revisioned. If bundle is nil, the charm will be removed; otherwise, it will be stored. It is an error to store a bundle under a charmURL that does not share its name and revision.

func (*MockCharmStore) WithAuthAttrs Uses

func (s *MockCharmStore) WithAuthAttrs(auth string) charm.Repository

func (*MockCharmStore) WithTestMode Uses

func (s *MockCharmStore) WithTestMode(testMode bool) charm.Repository

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

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

Repo represents a charm repository used for testing.

func (*Repo) Bundle Uses

func (r *Repo) Bundle(dst, name string) *charm.Bundle

Bundle returns an actual charm.Bundle created from a new charm bundle file created from the charm directory named name, in the directory dst.

func (*Repo) BundlePath Uses

func (r *Repo) BundlePath(dst, name string) string

BundlePath returns the path to a new charm bundle file created from the charm directory named name, in the directory dst.

func (*Repo) ClonedDir Uses

func (r *Repo) ClonedDir(dst, name string) *charm.Dir

ClonedDir returns an actual charm.Dir based on a new copy of the charm directory named name, in the directory dst.

func (*Repo) ClonedDirPath Uses

func (r *Repo) ClonedDirPath(dst, name string) string

ClonedDirPath returns the path to a new copy of the default charm directory named name.

func (*Repo) ClonedURL Uses

func (r *Repo) ClonedURL(dst, series, name string) *charm.URL

ClonedURL makes a copy of the charm directory. It will create a directory with the series name if it does not exist, and then clone the charm named name into that directory. The return value is a URL pointing at the local charm.

func (*Repo) Dir Uses

func (r *Repo) Dir(name string) *charm.Dir

Dir returns the actual charm.Dir named name.

func (*Repo) DirPath Uses

func (r *Repo) DirPath(name string) string

DirPath returns the path to a charm directory with the given name in the default series

func (*Repo) Path Uses

func (r *Repo) Path() string

func (*Repo) RenamedClonedDirPath Uses

func (r *Repo) RenamedClonedDirPath(dst, name, newName string) string

RenamedClonedDirPath returns the path to a new copy of the default charm directory named name, but renames it to newName.

type Response Uses

type Response struct {
    Status  int
    Headers map[string]string
    Body    []byte
}

type ResponseFunc Uses

type ResponseFunc func(path string) Response

type ResponseMap Uses

type ResponseMap map[string]Response

ResponseMap maps request paths to responses.

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

type TestFile struct {
    Name, Data string
}

Directories

PathSynopsis
checkers
testbase

Package testing imports 37 packages (graph). Updated 2017-06-09. Refresh now. Tools for package owners.