testserver

package
v0.0.0-...-fb05294 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 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 TestServer

type TestServer struct {
	// contains filtered or unexported fields
}

TestServer 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 TestServer is used the SetPath method must be called to define the location for the database files to be stored.

func (*TestServer) Session

func (ts *TestServer) 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 TestServer will start it.

func (*TestServer) SetPath

func (ts *TestServer) 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 (*TestServer) Stop

func (ts *TestServer) 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 (*TestServer) Wipe

func (ts *TestServer) 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