Help us shape the future of Go! Take the 2026 Go Developer Survey

mgotest

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2022 License: LGPL-3.0 Imports: 7 Imported by: 0

README

Simple support for Go testing with a live MongoDB database
----

This package makes it straightforward to write tests that connect
to a fresh MongoDB database created for the tests.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDisabled = errgo.New("MongoDB testing is disabled")

Functions

This section is empty.

Types

type Database

type Database struct {
	*mgo.Database
	// contains filtered or unexported fields
}

func New

func New() (*Database, error)

New connects to a MongoDB instance and returns a database instance that uses it. The database name is randomly chosen; all collections in the database will be removed when Close is called.

The environment variable MGOCONNECTIONSTRING will be consulted to determine the connection string to use (see https://docs.mongodb.com/manual/reference/connection-string/ or https://godoc.org/github.com/juju/mgo/v2#Dial for details of the format).

If MGOCONNECTIONSTRING is empty, "localhost" will be used.

If the environment variable MGOTESTDISABLE is non-empty, an error with a cause of ErrDisabled will be returned.

func NewExclusive

func NewExclusive() (*Database, error)

NewExclusive is like New except that it always returns a session is freshly created, rather than using one that's shared with other tests.

func (*Database) Close

func (db *Database) Close() error

Close drops the database and closes its associated session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL