Documentation
¶
Index ¶
- Constants
- Variables
- func Context(c *C) *cmd.Context
- func ContextForDir(c *C, dir string) *cmd.Context
- func EnvironConfig(c *C) *config.Config
- func FindTCPPort() int
- func HomePath(names ...string) string
- func InitCommand(c cmd.Command, args []string) error
- func MatchInstances(c *C, result []instance.Instance, expected ...instance.Instance)
- func MgoDial() *mgo.Session
- func MgoReset()
- func MgoTestPackage(t *stdtesting.T)
- func NewFlagSet() *gnuflag.FlagSet
- func RunCommand(c *C, com cmd.Command, args []string) (*cmd.Context, error)
- func RunCommandInDir(c *C, com cmd.Command, args []string, dir string) (*cmd.Context, error)
- func Stderr(ctx *cmd.Context) string
- func Stdout(ctx *cmd.Context) string
- func TarGz(files ...*TarFile) []byte
- func TestInit(c *C, com cmd.Command, args []string, errPat string)
- func TestLockingFunction(lock *sync.Mutex, function func())
- type ContentAsserterC
- type FakeHome
- func MakeEmptyFakeHome(c *C) *FakeHome
- func MakeEmptyFakeHomeWithoutJuju(c *C) *FakeHome
- func MakeFakeHome(c *C, envConfig string, certNames ...string) *FakeHome
- func MakeFakeHomeNoEnvironments(c *C, certNames ...string) *FakeHome
- func MakeFakeHomeWithFiles(c *C, files []TestFile) *FakeHome
- func MakeMultipleEnvHome(c *C) *FakeHome
- func MakeSampleHome(c *C) *FakeHome
- type GitSuite
- type HTTPServer
- func (s *HTTPServer) Flush()
- func (s *HTTPServer) Response(status int, headers map[string]string, body []byte)
- func (s *HTTPServer) ResponseFunc(n int, f ResponseFunc)
- func (s *HTTPServer) ResponseMap(n int, m ResponseMap)
- func (s *HTTPServer) Responses(n int, status int, headers map[string]string, body []byte)
- func (s *HTTPServer) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (s *HTTPServer) Start()
- func (s *HTTPServer) WaitRequest() *http.Request
- func (s *HTTPServer) WaitRequests(n int) []*http.Request
- type HTTPSuite
- type LoggingSuite
- type MgoSuite
- type MockCharmStore
- type NotifyAsserterC
- type Repo
- func (r *Repo) Bundle(dst, name string) *charm.Bundle
- func (r *Repo) BundlePath(dst, name string) string
- func (r *Repo) ClonedDir(dst, name string) *charm.Dir
- func (r *Repo) ClonedDirPath(dst, name string) string
- func (r *Repo) ClonedURL(dst, series, name string) *charm.URL
- func (r *Repo) Dir(name string) *charm.Dir
- func (r *Repo) DirPath(name string) string
- func (r *Repo) RenamedClonedDirPath(dst, name, newName string) string
- type Response
- type ResponseFunc
- type ResponseMap
- type TarFile
- type TestFile
Constants ¶
const EnvDefault = "default:\n " + SampleEnvName + "\n"
const LongWait = 500 * time.Millisecond
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 = `` /* 301-byte string literal not displayed */
const SampleCertName = "erewhemos"
const SampleEnvName = "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 = `` /* 157-byte string literal not displayed */
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 ( // MgoAddr holds the address of the shared MongoDB server set up by // MgoTestPackage. MgoAddr string )
var Server = NewHTTPServer(5 * time.Second)
Functions ¶
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 EnvironConfig ¶
EnvironConfig returns a default environment configuration suitable for testing.
func FindTCPPort ¶
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 InitCommand ¶
InitCommand will create a new flag set, and call the Command's SetFlags and Init methods with the appropriate args.
func MatchInstances ¶
MatchInstances uses DeepEquals to check the instances returned. The lists are first put into a map, so the ordering of the result and expected values is not tested, and duplicates are ignored.
func MgoTestPackage ¶
func MgoTestPackage(t *stdtesting.T)
MgoTestPackage should be called to register the tests for any package that requires a MongoDB server.
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 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 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.
Types ¶
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 <-chan interface{} // Precond will be called before waiting on the channel, can be nil Precond func() }
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) 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 FakeHome ¶
type FakeHome struct {
// contains filtered or unexported fields
}
func MakeEmptyFakeHome ¶
func MakeEmptyFakeHome(c *C) *FakeHome
func MakeEmptyFakeHomeWithoutJuju ¶
func MakeEmptyFakeHomeWithoutJuju(c *C) *FakeHome
func MakeFakeHome ¶
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 ¶
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 ¶
func MakeMultipleEnvHome ¶
func MakeMultipleEnvHome(c *C) *FakeHome
func MakeSampleHome ¶
func MakeSampleHome(c *C) *FakeHome
func (*FakeHome) FileContents ¶
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 ¶
FileExists returns if the given relative file path exists in the fake home.
type GitSuite ¶
type GitSuite struct {
// contains filtered or unexported fields
}
func (*GitSuite) TearDownTest ¶
func (t *GitSuite) TearDownTest(c *C)
type HTTPServer ¶
type HTTPServer struct { URL string Timeout time.Duration // contains filtered or unexported fields }
func NewHTTPServer ¶
func NewHTTPServer(timeout time.Duration) *HTTPServer
func (*HTTPServer) Flush ¶
func (s *HTTPServer) Flush()
Flush discards all pending requests and responses.
func (*HTTPServer) Response ¶
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 ¶
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 ¶
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 ¶
Responses prepares the test server to respond the following n requests using the provided response parameters.
func (*HTTPServer) ServeHTTP ¶
func (s *HTTPServer) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*HTTPServer) Start ¶
func (s *HTTPServer) Start()
func (*HTTPServer) WaitRequest ¶
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 ¶
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 ¶
type HTTPSuite struct{}
func (*HTTPSuite) SetUpSuite ¶
func (s *HTTPSuite) SetUpSuite(c *C)
func (*HTTPSuite) TearDownSuite ¶
func (s *HTTPSuite) TearDownSuite(c *C)
func (*HTTPSuite) TearDownTest ¶
func (s *HTTPSuite) TearDownTest(c *C)
type LoggingSuite ¶
type LoggingSuite struct {
// contains filtered or unexported fields
}
LoggingSuite redirects the juju logger to the test logger when embedded in a gocheck suite type.
func (*LoggingSuite) SetUpSuite ¶
func (t *LoggingSuite) SetUpSuite(c *C)
func (*LoggingSuite) SetUpTest ¶
func (t *LoggingSuite) SetUpTest(c *C)
func (*LoggingSuite) TearDownSuite ¶
func (t *LoggingSuite) TearDownSuite(c *C)
func (*LoggingSuite) TearDownTest ¶
func (t *LoggingSuite) TearDownTest(c *C)
type MgoSuite ¶
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 ¶
func (s *MgoSuite) SetUpSuite(c *C)
func (*MgoSuite) TearDownSuite ¶
func (s *MgoSuite) TearDownSuite(c *C)
func (*MgoSuite) TearDownTest ¶
func (s *MgoSuite) TearDownTest(c *C)
type MockCharmStore ¶
type MockCharmStore struct {
// contains filtered or unexported fields
}
MockCharmStore implements charm.Respository and is used to isolate tests that would otherwise need to hit the real charm store.
func NewMockCharmStore ¶
func NewMockCharmStore() *MockCharmStore
func (*MockCharmStore) Latest ¶
func (s *MockCharmStore) Latest(charmURL *charm.URL) (int, error)
Latest implements charm.Repository.Latest.
func (*MockCharmStore) SetCharm ¶
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.
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 Repo ¶
type Repo struct {
Path string
}
Repo represents a charm repository used for testing.
var Charms *Repo
Charms represents the specific charm repository stored in this package and used by the Juju unit tests. The series name is "series".
func (*Repo) 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 ¶
BundlePath returns the path to a new charm bundle file created from the charm directory named name, in the directory dst.
func (*Repo) ClonedDir ¶
ClonedDir returns an actual charm.Dir based on a new copy of the charm directory named name, in the directory dst.
func (*Repo) ClonedDirPath ¶
ClonedDirPath returns the path to a new copy of the default charm directory named name.
func (*Repo) ClonedURL ¶
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) DirPath ¶
DirPath returns the path to a charm directory with the given name in the default series
func (*Repo) RenamedClonedDirPath ¶
RenamedClonedDirPath returns the path to a new copy of the default charm directory named name, but renames it to newName.
type ResponseFunc ¶
type ResponseMap ¶
ResponseMap maps request paths to responses.