temp
This commit is contained in:
49
Server/common/db/test_db.go
Normal file
49
Server/common/db/test_db.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"common/config"
|
||||
"common/db/mongo"
|
||||
"common/db/mysql"
|
||||
"common/log"
|
||||
"common/utils"
|
||||
"fmt"
|
||||
"github.com/jinzhu/configor"
|
||||
"math/rand"
|
||||
"os"
|
||||
)
|
||||
|
||||
// 用于单元测试初始化数据库
|
||||
|
||||
func InitTestDB(env string) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Println("无法获取工作目录:", err)
|
||||
return
|
||||
}
|
||||
|
||||
var commonCfg config.CommonConfig
|
||||
err = configor.Load(&commonCfg, fmt.Sprintf(wd+"/config/common-config-%v.json", env))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
log.Init(&commonCfg.Logger)
|
||||
utils.InitSnowflake(int64(rand.Intn(1000)))
|
||||
//// Redis
|
||||
//if err := redis.Init(&commonCfg.Redis); err != nil {
|
||||
// panic(err)
|
||||
//}
|
||||
// MySQL
|
||||
if err := mysql.Init(&commonCfg.MysqlConfig); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Mongo
|
||||
if err := mongo.Init(&commonCfg.MongoConfig); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
//// Etcd
|
||||
//if err := etcd.Init(&commonCfg.Etcd); err != nil {
|
||||
// panic(err)
|
||||
//}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user