Documentation ¶
Index ¶
- type MongoSuite
- func (suite *MongoSuite) DB() *mgo.Database
- func (suite *MongoSuite) DBServer() *dbtest.DBServer
- func (suite *MongoSuite) InsertFixture(collection string, pathToFixture string, doc interface{})
- func (suite *MongoSuite) PrintDBServerInfo()
- func (suite *MongoSuite) TearDownDB()
- func (suite *MongoSuite) TearDownDBServer()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MongoSuite ¶
MongoSuite is a testify Suite that adds functions to setup and teardown test Mongo DBs, as well as other provides functions for other common Mongo-related tasks such as inserting a fixture into the database.
func (*MongoSuite) DB ¶
func (suite *MongoSuite) DB() *mgo.Database
DB returns a pointer to the suite's test Database, named "ptmerge-test", initializing a new Database, Session, and/or DBServer if necessary. Subsequent calls will return the same Database until TearDownDB() is called. If a test suite calls DB(), then TearDownDBServer() MUST be called in the TearDownSuite function (or TearDownTest, if appropriate).
func (*MongoSuite) DBServer ¶
func (suite *MongoSuite) DBServer() *dbtest.DBServer
DBServer returns a pointer to the suite's test Mongo DBServer, initializing a new one if necessary. Subsequent calls will return the same DBServer until TearDownDBServer is called. In most cases, calls to DBServer() are completely unnecessary, as calls to DB() will automatically instantiate the DBServer if needed. If a test suite calls DBServer(), then TearDownDBServer() MUST be called in the TearDownSuite function (or TearDownTest, if appropriate).
func (*MongoSuite) InsertFixture ¶
func (suite *MongoSuite) InsertFixture(collection string, pathToFixture string, doc interface{})
InsertFixture inserts a test fixture into the Mongo database. If the fixture does not have an _id set, InsertFixture will attempt to find the _id field using reflection and will set it to a new BSON ID before inserting.
func (*MongoSuite) PrintDBServerInfo ¶
func (suite *MongoSuite) PrintDBServerInfo()
PrintDBServerInfo logs out the connection info for the current test database.
func (*MongoSuite) TearDownDB ¶
func (suite *MongoSuite) TearDownDB()
TearDownDB closes the suite's test Session and wipes the DBServer (thereby removing the Database). This function would typically be called in the test suite's TearDownTest function.
func (*MongoSuite) TearDownDBServer ¶
func (suite *MongoSuite) TearDownDBServer()
TearDownDBServer cleans up the suite's test Mongo DBServer, including closing any open sessions, wiping the data, stopping the test DBServer, and deleting the temporary directory where the DBServer stored files. This function would typically be called in the test suite's TearDownSuite function.