上传 模块测试 模板

This commit is contained in:
liwei1dao 2022-06-14 17:33:22 +08:00
parent 7081e9a8cb
commit 3bf2feba6b

View File

@ -1,35 +1,72 @@
package pack_test package pack
import ( import (
"fmt" "fmt"
"go_dreamfactory/lego/sys/mgo" "go_dreamfactory/lego"
"go_dreamfactory/lego/sys/redis" "go_dreamfactory/lego/base/rpcx"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/services"
"go_dreamfactory/sys/cache"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
"go_dreamfactory/sys/db"
"os" "os"
"testing" "testing"
"time"
) )
var db mgo.ISys func newService(ops ...rpcx.Option) core.IService {
var cache redis.ISys s := new(TestService)
s.Configure(ops...)
return s
}
//梦工厂基础服务对象
type TestService struct {
rpcx.RPCXService
}
//初始化相关系统
func (this *TestService) InitSys() {
this.RPCXService.InitSys()
if err := cache.OnInit(this.GetSettings().Sys["cache"]); err != nil {
panic(fmt.Sprintf("init sys.cache err: %s", err.Error()))
} else {
log.Infof("init sys.cache success!")
}
if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil {
panic(fmt.Sprintf("init sys.db err: %s", err.Error()))
} else {
log.Infof("init sys.db success!")
}
if err := configure.OnInit(this.GetSettings().Sys["configure"]); err != nil {
panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
} else {
log.Infof("init sys.configure success!")
}
}
var module = new(Pack)
//测试环境下初始化db和cache 系统 //测试环境下初始化db和cache 系统
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
var err error s := newService(
if db, err = mgo.NewSys(nil, mgo.SetMongodbUrl("mongodb://admin:123456@10.0.0.9:27018"), mgo.SetMongodbDatabase("dreamfactory")); err != nil { rpcx.SetConfPath("../../bin/conf/worker_1.yaml"),
fmt.Printf("err:%v\n", err) rpcx.SetVersion("1.0.0.0"),
return )
} s.OnInstallComp( //装备组件
if cache, err = redis.NewSys(nil, redis.SetRedisType(redis.Redis_Cluster), redis.SetRedis_Cluster_Addr([]string{"10.0.0.9:9001", "10.0.0.9:9002", "10.0.0.9:9003", "10.0.1.45:9004", "10.0.1.45:9005", "10.0.1.45:9006"}), redis.SetRedis_Cluster_Password("")); err != nil { services.NewGateRouteComp(), //此服务需要接受用户的消息 需要装备网关组件
fmt.Printf("err:%v\n", err) )
return go func() {
} lego.Run(s, //运行模块
if err := configure.OnInit(nil); err != nil { module,
fmt.Printf("err:%v\n", err) )
return }()
} time.Sleep(time.Second)
defer os.Exit(m.Run()) defer os.Exit(m.Run())
} }
func Test_Log(t *testing.T) { func Test_Log(t *testing.T) {
db.InsertOne("", 1) items, err := module.db_comp.Pack_QueryUserPack("liwei1dao")
log.Debugf("item:%v err:%v", items, err)
} }