Documentation ¶
Overview ¶
Package mongodb provides a shared MongoDB container for testing purposes. It includes the ability to create a new database off the shared container. This is particularly useful for running isolated tests against a fresh MongoDB instance.
Package mongodb provides a shared MongoDB container for testing purposes. It includes the ability to create a new database off the shared container. This is particularly useful for running isolated tests against a fresh MongoDB instance.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MongoEnvironment ¶
type MongoEnvironment struct { URI string // server address including scheme and port // contains filtered or unexported fields }
MongoEnvironment is a MongoDB test environment. It starts a single MongoDB container and provides a client to it.
func NewMongoEnvironment ¶
func NewMongoEnvironment() *MongoEnvironment
NewMongoEnvironment creates a new MongoDB test environment.
func (*MongoEnvironment) NewInstance ¶
func (m *MongoEnvironment) NewInstance() (*mongo.Database, context.CancelFunc)
NewInstance creates a new Mongo database. Make sure to call cancel function when done with the database.
func (*MongoEnvironment) Start ¶
func (m *MongoEnvironment) Start() (context.CancelFunc, error)
Start starts the MongoDB container and returns a function to stop it. Make sure to call the returned cancel function when done with the container, regardless of whether an error occurred.