github.com/seeker-insurance/kit@v0.0.13/db/mongo/mongotest/mongotest.go (about) 1 package mongotest 2 3 import ( 4 "sync/atomic" 5 "github.com/globalsign/mgo" 6 ) 7 8 var namespacer int64 9 10 func SetupTestDB(name string) *mgo.Database { 11 session, _ := mgo.Dial("mongodb://localhost/" + name) 12 db := session.DB("test") 13 db.DropDatabase() 14 return db 15 } 16 17 type TestDB struct { 18 *mgo.Database 19 } 20 21 func (db TestDB) TestCollection(v []interface{}) *mgo.Collection { 22 name := string(atomic.AddInt64(&namespacer, 1)) 23 c := db.C(name) 24 c.Insert(v...) 25 return c 26 }