go_dreamfactory/modules/hero/hero_test.go
2022-06-29 10:27:59 +08:00

101 lines
2.4 KiB
Go

package hero
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego"
"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/db"
"os"
"testing"
"time"
)
var service core.IService
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
var module = new(Hero)
type TestService struct {
rpcx.RPCXService
}
func newService(ops ...rpcx.Option) core.IService {
s := new(TestService)
s.Configure(ops...)
return s
}
//初始化相关系统
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"], configure.SetConfigPath("E:\\projects\\workspace\\go_dreamfactory\\bin\\json")); err != nil {
panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
} else {
log.Infof("init sys.configure success!")
}
}
func TestMain(m *testing.M) {
service = newService(
rpcx.SetConfPath("../../bin/conf/worker_2.yaml"),
)
service.OnInstallComp( //装备组件
s_gateComp, //此服务需要接受用户的消息 需要装备网关组件
)
go func() {
lego.Run(service, //运行模块
module,
//
)
}()
time.Sleep(time.Second * 2)
defer os.Exit(m.Run())
}
//创建一个英雄s
func TestCreateOneHero(t *testing.T) {
err := module.modelHero.createOneHero("u1", 25001)
fmt.Println(err)
}
//获取玩家英雄
func TestGetOneHero(t *testing.T) {
d := module.modelHero.getOneHero("u1", "62b534bebf4745d4117acabe")
fmt.Printf("%v", d)
}
func TestPropertyCompute(t *testing.T) {
m := module.modelHero.PropertyCompute("u1", "62b534bebf4745d4117acabe")
fmt.Println(m)
}
func TestHeroList(t *testing.T) {
heroes, err := module.modelHero.getHeroList("u1")
fmt.Printf("%v %v", heroes, err)
}
func TestModify(t *testing.T) {
data := map[string]interface{}{
"lv": 2,
"exp": 1000,
}
err := module.modelHero.modifyHero("u1", "62b534bebf4745d4117acabe", data)
fmt.Printf("%v ", err)
}