go_dreamfactory/modules/equipment/module_test.go

108 lines
3.2 KiB
Go

package equipment_test
import (
"context"
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego"
"go_dreamfactory/lego/base/rpcx"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules/equipment"
"go_dreamfactory/modules/hero"
"go_dreamfactory/modules/items"
"go_dreamfactory/modules/user"
"go_dreamfactory/pb"
"go_dreamfactory/services"
"go_dreamfactory/sys/configure"
"go_dreamfactory/sys/db"
"os"
"testing"
"time"
"github.com/golang/protobuf/ptypes"
)
func newService(ops ...rpcx.Option) core.IService {
s := new(TestService)
s.Configure(ops...)
return s
}
//梦工厂基础服务对象
type TestService struct {
rpcx.RPCXService
}
//初始化相关系统
func (this *TestService) InitSys() {
this.RPCXService.InitSys()
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"], configure.SetConfigPath("F:/work/go/go_dreamfactory/bin/json")); err != nil {
panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
} else {
log.Infof("init sys.configure success!")
}
}
var service core.IService
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
var module = new(equipment.Equipment)
//测试环境下初始化db和cache 系统
func TestMain(m *testing.M) {
service = newService(
rpcx.SetConfPath("../../bin/conf/worker_1.yaml"),
rpcx.SetVersion("1.0.0.0"),
)
service.OnInstallComp( //装备组件
s_gateComp, //此服务需要接受用户的消息 需要装备网关组件
)
go func() {
lego.Run(service, //运行模块
module,
hero.NewModule(),
user.NewModule(),
items.NewModule(),
)
}()
time.Sleep(time.Second * 3)
defer os.Exit(m.Run())
}
//测试协议 查询武器
func Test_Modules_EquipmentGetListReq(t *testing.T) {
data, _ := ptypes.MarshalAny(&pb.EquipmentGetListReq{})
reply := &pb.RPCMessageReply{}
s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62b16dda909b2f8faeff788d", MainType: "equipment", SubType: "getlist", Message: data}, reply)
log.Debugf("Test_Modules_Proro reply:%v", reply)
}
//测试协议 武器升级
func Test_Modules_EquipmentUpgradeReq(t *testing.T) {
data, _ := ptypes.MarshalAny(&pb.EquipmentUpgradeReq{EquipmentId: "62bd82860863ffbf2eb67f3a"})
reply := &pb.RPCMessageReply{}
s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62b16dda909b2f8faeff788d", MainType: "equipment", SubType: "upgrade", Message: data}, reply)
log.Debugf("Test_Modules_Proro reply:%v", reply)
}
//添加武器测试
func Test_Module_AddNewEquipments(t *testing.T) {
// code := module.AddNewEquipments(&comm.ModuleCallSource{
// Module: "Test",
// FuncName: "Test_Module",
// Describe: "摸底测试",
// }, "0_62b16dda909b2f8faeff788d", map[int32]uint32{10001: 1}, true)
// log.Debugf("Test_Module Code:%d", code)
}
//查询武器信息
func Test_Module_QueryEquipment(t *testing.T) {
equipment, code := module.QueryEquipment("0_62b16dda909b2f8faeff788d", "62bd82860863ffbf2eb67f3a")
log.Debugf("Test_Module equipment:%v code:%d", equipment, code)
}