Documentation
¶
Index ¶
- Constants
- Variables
- func FindTCPPort() int
- func MgoDialInfo(certs *Certs, addrs ...string) *mgo.DialInfo
- func MgoTestPackage(t *testing.T, certs *Certs)
- func MongodVersion() (version.Number, error)
- type Certs
- type IsolatedMgoSuite
- type MgoInstance
- func (m *MgoInstance) Addr() string
- func (inst *MgoInstance) Destroy()
- func (inst *MgoInstance) DestroyWithLog()
- func (inst *MgoInstance) Dial() (*mgo.Session, error)
- func (inst *MgoInstance) DialDirect() (*mgo.Session, error)
- func (inst *MgoInstance) DialInfo() *mgo.DialInfo
- func (inst *MgoInstance) EnsureRunning() error
- func (inst *MgoInstance) MustDial() *mgo.Session
- func (inst *MgoInstance) MustDialDirect() *mgo.Session
- func (m *MgoInstance) Port() int
- func (inst *MgoInstance) Reset() error
- func (inst *MgoInstance) Restart()
- func (m *MgoInstance) SSLEnabled() bool
- func (inst *MgoInstance) Start(certs *Certs) error
- type MgoSuite
- type ProxiedSession
Constants ¶
const (
// The default password to use when connecting to the mongo database.
DefaultMongoPassword = "conn-from-name-secret"
)
Variables ¶
var ( // MgoServer is a shared mongo server used by tests. MgoServer = &MgoInstance{} )
Functions ¶
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 MgoDialInfo ¶
MgoDialInfo returns a DialInfo suitable for dialling an MgoInstance at any of the given addresses, optionally using TLS.
func MgoTestPackage ¶
MgoTestPackage should be called to register the tests for any package that requires a MongoDB server. If certs is non-nil, a secure SSL connection will be used from client to server.
func MongodVersion ¶
func MongodVersion() (version.Number, error)
Types ¶
type Certs ¶
type Certs struct { // CACert holds the CA certificate. This must certify the private key that // was used to sign the server certificate. CACert *x509.Certificate // ServerCert holds the certificate that certifies the server's // private key. ServerCert *x509.Certificate // ServerKey holds the server's private key. ServerKey *rsa.PrivateKey }
Certs holds the certificates and keys required to make a secure SSL connection.
type IsolatedMgoSuite ¶
type IsolatedMgoSuite struct { jujutesting.IsolationSuite MgoSuite }
IsolatedMgoSuite is a convenience type that combines the functionality IsolationSuite and MgoSuite.
func (*IsolatedMgoSuite) SetUpSuite ¶
func (s *IsolatedMgoSuite) SetUpSuite(c *gc.C)
func (*IsolatedMgoSuite) SetUpTest ¶
func (s *IsolatedMgoSuite) SetUpTest(c *gc.C)
func (*IsolatedMgoSuite) TearDownSuite ¶
func (s *IsolatedMgoSuite) TearDownSuite(c *gc.C)
func (*IsolatedMgoSuite) TearDownTest ¶
func (s *IsolatedMgoSuite) TearDownTest(c *gc.C)
type MgoInstance ¶
type MgoInstance struct { // Params is a list of additional parameters that will be passed to // the mongod application Params []string // EnableReplicaSet will pass the right parameters to --replSet and call // replSetInitiate when appropriate. EnableReplicaSet bool // EnableAuth enables authentication/authorization. EnableAuth bool // WithoutV8 is true if we believe this Mongo doesn't actually have the // V8 engine WithoutV8 bool // MaxTransactionLockRequestTimeout is used for the mongo // maxTransactionLockRequestTimeoutMillis server setting (v4+). MaxTransactionLockRequestTimeout time.Duration // contains filtered or unexported fields }
func (*MgoInstance) Addr ¶
func (m *MgoInstance) Addr() string
Addr returns the address of the MongoDB server.
func (*MgoInstance) Destroy ¶
func (inst *MgoInstance) Destroy()
Destroy kills mongod and cleans up its data directory.
func (*MgoInstance) DestroyWithLog ¶
func (inst *MgoInstance) DestroyWithLog()
DestroyWithLog causes mongod to exit, cleans up its data directory, and captures the last N lines of mongod's log output.
func (*MgoInstance) Dial ¶
func (inst *MgoInstance) Dial() (*mgo.Session, error)
Dial returns a new connection to the MongoDB server.
func (*MgoInstance) DialDirect ¶
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) DialInfo ¶
func (inst *MgoInstance) DialInfo() *mgo.DialInfo
DialInfo returns information suitable for dialling the receiving MongoDB instance.
func (*MgoInstance) EnsureRunning ¶
func (inst *MgoInstance) EnsureRunning() error
func (*MgoInstance) MustDial ¶
func (inst *MgoInstance) MustDial() *mgo.Session
MustDial returns a new connection to the MongoDB server, and panics on errors.
func (*MgoInstance) MustDialDirect ¶
func (inst *MgoInstance) MustDialDirect() *mgo.Session
MustDialDirect works like DialDirect, but panics on errors.
func (*MgoInstance) Port ¶
func (m *MgoInstance) Port() int
Port returns the port of the MongoDB server.
func (*MgoInstance) Reset ¶
func (inst *MgoInstance) Reset() error
Reset deletes all content from the MongoDB server.
func (*MgoInstance) Restart ¶
func (inst *MgoInstance) Restart()
Restart restarts the mongo server, useful for testing what happens when a state server goes down.
func (*MgoInstance) SSLEnabled ¶
func (m *MgoInstance) SSLEnabled() bool
SSLEnabled reports whether or not SSL is enabled for the MongoDB server.
func (*MgoInstance) Start ¶
func (inst *MgoInstance) Start(certs *Certs) error
Start starts a MongoDB server in a temporary directory.
type MgoSuite ¶
type MgoSuite struct { Session *mgo.Session // DebugMgo controls whether SetUpSuite enables mgo logging and // debugging. Set this before calling SetUpSuite. Enabling either // logging or debugging in mgo adds a significant overhead to the // Juju tests, so they are disabled by default. DebugMgo bool // SkipTestCleanup controls collection cleanup in TearDownTest. // When set to true, TearDownTest will not delete collections. SkipTestCleanup bool }
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 (*MgoSuite) TearDownSuite ¶
func (*MgoSuite) TearDownTest ¶
type ProxiedSession ¶
type ProxiedSession struct { *mgo.Session *jujutesting.TCPProxy }
ProxiedSession represents a mongo session that's proxied through a TCPProxy instance.
func NewProxiedSession ¶
func NewProxiedSession(c *gc.C) *ProxiedSession
NewProxiedSession returns a ProxiedSession instance that holds a mgo.Session that directs through a TCPProxy instance to the testing mongoDB server, and the proxy instance itself. This allows tests to check what happens when mongo connections are broken.
The returned value should be closed after use.
func (*ProxiedSession) Close ¶
func (s *ProxiedSession) Close()
Close closes s.Session and s.TCPProxy.