bug fix: fixed mongo.go unit test

This commit is contained in:
hantmac
2019-08-19 09:56:16 +08:00
parent 419c667e83
commit 3fa7b535f4

View File

@@ -1,6 +1,7 @@
package database
import (
"crawlab/config"
. "github.com/smartystreets/goconvey/convey"
"github.com/spf13/viper"
"testing"
@@ -8,12 +9,20 @@ import (
func TestGetDb(t *testing.T) {
Convey("Test GetDb", t, func() {
if err := config.InitConfig(""); err != nil {
t.Fatal("Init config failed")
}
t.Log("初始化配置成功")
err := InitMongo()
if err != nil {
t.Fatal("Init mongodb failed")
}
s, db := GetDb()
Convey("The value should be Session.Copy", func() {
So(s, ShouldEqual, Session.Copy())
So(s, ShouldResemble, Session.Copy())
})
Convey("The value should be reference of database", func() {
So(db, ShouldEqual, s.DB(viper.GetString("mongo.db")))
So(db, ShouldResemble, s.DB(viper.GetString("mongo.db")))
})
})
}