Documentation ¶
Overview ¶
Package mongotest provides helpers for running regressions using mongo. You can find helpers for: - ?running a database using docker - importing data from files - cleaning up a database
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFailedToConnectToDockerDaemon denotes that we couldn't connect to the docker daemon // running locally on the machine. ErrFailedToConnectToDockerDaemon = errors.New("could not connect to docker daemon") // ErrNoAvailablePorts denotes that no ports were available for binding the docker mongo instance to ErrNoAvailablePorts = errors.New("no ports are available to bind the docker mongo instance to") // ErrMongoContainerAlreadyRunning ErrMongoContainerAlreadyRunning = errors.New("the mongo container is already running - an attempt was made to call it a second time") )
Functions ¶
func GetAvailablePort ¶
GetAvailablePort returns an available port on the system.
Types ¶
type MongoTestError ¶
type MongoTestError struct {
// contains filtered or unexported fields
}
func NewMongoTestError ¶
func NewMongoTestError(err error) *MongoTestError
func (*MongoTestError) Unwrap ¶
func (mte *MongoTestError) Unwrap() error
type TestConnection ¶
type TestConnection struct { *easymongo.Connection // contains filtered or unexported fields }
TestConnection contains helpers for creating your own tests with mongo.
func NewTestConnection ¶
func NewTestConnection(spinupDockerContainer bool) (*TestConnection, error)
NewTestConnection is the standard method for initializing a TestConnection - it has a side-effect of spawning a new docker container if spinupDockerContainer is set to true. Note that the first time this is called on a new system, the mongo docker container will be pulled. Any subsequent calls on the system should succeed without calls to pull. If spinupDockerContainer is False, then no docker shenanigans occur, instead an attempt is made to connect to a locally running mongo instance (e.g. mongodb://127.0.0.1:27017).
func (*TestConnection) KillMongoContainer ¶
func (tc *TestConnection) KillMongoContainer() (err error)
KillMongoContainer tears down the specified container TODO: Is there some nifty hook I could use that allows me to always call this as the scope of a test exits?
func (*TestConnection) MongoContainerID ¶
func (tc *TestConnection) MongoContainerID() string
MongoContainerID returns the ID of the running docker container If no container is running, an empty string will be returned.
func (*TestConnection) StartMongoContainer ¶
func (tc *TestConnection) StartMongoContainer(portNumber int) (containerID string, err error)
StartMongoContainer starts a mongo docker container A note that the docker daemon on the system is expected to be running TODO: Is there a way to spawn the docker daemon myself?