dbtest

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2015 License: BSD-2-Clause, MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL