testdb

package
v0.0.0-...-78bde44 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package testdb helps unit test with mongo db, by recreate mongo db.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Test

func Test(f func(db *TestDB, t *testing.T)) tt.TestFunction

Test create a test function that uses of mongodb

Types

type TestDB

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

TestDB create a connection to mongodb, and delete the database in reset. Also provide mongodb operation methods, so we do not need to deal with returned error. *mgo.Databae is nested in, so all Database method con be used directly from TestDB, such as:

db := testdb.New("blah_test")
db.C("tbl").Insert(...

Instead of:

db.Session.DB("").C("tbl").Insert(...

func New

func New() *TestDB

New TestDB instance.

func (*TestDB) Close

func (db *TestDB) Close() error

Close TestDB.

Jump to

Keyboard shortcuts

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