mgo.v2: gopkg.in/mgo.v2/dbtest Index | Files

package dbtest

import "gopkg.in/mgo.v2/dbtest"

Index

Package Files

dbserver.go

type DBServer Uses

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 Uses

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 Uses

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 Uses

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 Uses

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.

Package dbtest imports 9 packages (graph) and is imported by 5 packages. Updated 2019-03-18. Refresh now. Tools for package owners.