Version: v0.0.0-...-086e3dd Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2020 License: BSD-2-Clause Imports: 10 Imported by: 0




This section is empty.


This section is empty.


This section is empty.


type DBServer

type DBServer struct {
	// contains filtered or unexported fields

DBServer controls a MongoDB server process to be used within test suites.

The test server is started when Session is called the first time and should remain running for the duration of all tests, with the Wipe method being called between tests (before each of them) to clear stored data. After all tests are done, the Stop method should be called to stop the test server.

Before the DBServer is used the SetPath method must be called to define the location for the database files to be stored.

func (*DBServer) EnableReplicaset

func (dbs *DBServer) EnableReplicaset(name string)

EnableReplicaset must be called before the database is started. It will start the server with '--replSet=<name>' and then call rs.initiate() once the server is up and running. Note that mongod startup time is significantly slower in replSet mode, but it is necessary for some things like Transaction support.

func (*DBServer) Session

func (dbs *DBServer) Session() *mgo.Session

Session returns a new session to the server. The returned session must be closed after the test is done with it.

The first Session obtained from a DBServer will start it.

func (*DBServer) SetPath

func (dbs *DBServer) SetPath(dbpath string)

SetPath defines the path to the directory where the database files will be stored if it is started. The directory path itself is not created or removed by the test helper.

func (*DBServer) Stop

func (dbs *DBServer) Stop()

Stop stops the test server process, if it is running.

It's okay to call Stop multiple times. After the test server is stopped it cannot be restarted.

All database sessions must be closed before or while the Stop method is running. Otherwise Stop will panic after a timeout informing that there is a session leak.

func (*DBServer) Wipe

func (dbs *DBServer) Wipe()

Wipe drops all created databases and their data.

The MongoDB server remains running if it was prevoiusly running, or stopped if it was previously stopped.

All database sessions must be closed before or while the Wipe method is running. Otherwise Wipe will panic after a timeout informing that there is a session leak.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL