接口测试

This commit is contained in:
zhaocy 2022-07-15 16:43:02 +08:00
parent 02c8ef307b
commit 33c781d457
3 changed files with 55 additions and 40 deletions

View File

@ -68,7 +68,7 @@ var (
mainType: string(comm.ModuleHero),
subType: hero.HeroSubTypeChouka,
req: &pb.HeroChoukaReq{
HeroIds: []int32{42911},
HeroIds: []int32{14001, 14002, 14003, 14004, 14005, 14006, 14007},
},
rsp: &pb.HeroChoukaResp{},
// enabled: true,
@ -78,7 +78,7 @@ var (
subType: hero.HeroSubTypeList,
req: &pb.HeroListReq{},
rsp: &pb.HeroListResp{},
enabled: true,
// enabled: true,
next: func(robot *Robot, rsp proto.Message) {
if r, ok := rsp.(*pb.HeroListResp); ok {
tcs := []*TestCase{}
@ -94,11 +94,13 @@ var (
HeroRace: []*pb.CostCardData{
{
CostCardObj: heroId,
Amount: 1,
},
},
Hero: []*pb.CostCardData{
{
CostCardObj: heroId,
Amount: 1,
},
},
},
@ -111,18 +113,35 @@ var (
}
},
}, {
// enabled: true,
}, {
desc: "英雄列表",
mainType: string(comm.ModuleHero),
subType: hero.StrengthenUplv,
req: &pb.HeroStrengthenUplvReq{
HeroObjID: "62bd0489ff6632434a7d0d1f",
ExpCardID: "62bd0b4eca37634b8230d4be",
Amount: 1,
subType: hero.HeroSubTypeList,
req: &pb.HeroListReq{},
rsp: &pb.HeroListResp{},
enabled: true,
next: func(robot *Robot, rsp proto.Message) {
if r, ok := rsp.(*pb.HeroListResp); ok {
tcs := []*TestCase{}
// selHero := r.List[0] //选中的英雄
for _, v := range r.List {
heroId := v.Id
tc := &TestCase{
desc: "英雄升级",
mainType: string(comm.ModuleHero),
subType: hero.StrengthenUplv,
req: &pb.HeroStrengthenUplvReq{
HeroObjID: heroId,
ExpCardID: "62d124700625e43054ba307d",
Amount: 1,
},
rsp: &pb.HeroStrengthenUplvResp{},
enabled: true,
}
tcs = append(tcs, tc)
}
robot.addBuilders(tcs)
}
},
rsp: &pb.HeroStrengthenUplvResp{},
// enabled: true,
},
}
)

View File

@ -53,6 +53,7 @@ func initlog() {
writers := []io.Writer{
file,
os.Stdout}
//同时写文件和屏幕
fileAndStdoutWriter := io.MultiWriter(writers...)
if err == nil {
@ -93,12 +94,6 @@ func (r *Robot) Run() {
r.AccountLogin()
}
// go func() {
// for {
// r.handleRsp()
// }
// }()
ticker := time.NewTicker(time.Second * 5)
go func() {
for {
@ -120,18 +115,17 @@ func (r *Robot) Run() {
}
type TestCase struct {
id string //用例ID 如果没有指定,会自动赋值uuid
desc string //用例描述
mainType string //协议类型 L1
subType string //协议类型 L2
req proto.Message //请求类型
rsp proto.Message //响应类型
enabled bool //是否启用
start time.Time //启用时间
hs time.Duration //耗时
// requested bool //是否是请求的case
print func(rsp proto.Message) //定义打印
next func(robot *Robot, rsp proto.Message) //处理下一层用例请求
id string //用例ID 如果没有指定,会自动赋值uuid
desc string //用例描述
mainType string //协议类型 L1
subType string //协议类型 L2
req proto.Message //请求类型
rsp proto.Message //响应类型
enabled bool //是否启用
start time.Time //启用时间
hs time.Duration //耗时
print func(rsp proto.Message) //定义打印
next func(robot *Robot, rsp proto.Message) //处理下一层用例请求
}
//添加测试用用例
@ -162,7 +156,6 @@ func (r *Robot) handleReq() {
for _, b := range r.builderMap {
if b.enabled && b.req != nil {
time.Sleep(time.Millisecond * 500)
// r.reqCh <- b.id
b.start = time.Now()
r.start = time.Now()
head := &pb.UserMessage{MainType: b.mainType, SubType: b.subType}
@ -229,7 +222,6 @@ func (r *Robot) handleRsp(id string) {
uuid = id
}
// uuid := <-r.reqCh
r.handleNotify(uuid, msg)
if v, ok := r.builderMap[uuid]; ok {
if v.enabled &&

View File

@ -1,7 +1,6 @@
package robot
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/modules/task"
"go_dreamfactory/pb"
@ -12,7 +11,6 @@ import (
var (
taskBuilders = []*TestCase{
{
//list
desc: "任务列表",
mainType: string(comm.ModuleTask),
subType: task.TaskSubTypeList,
@ -20,13 +18,19 @@ var (
TaskTag: int32(comm.TASK_DAILY),
},
rsp: &pb.TaskListResp{},
print: func(rsp proto.Message) {
out := rsp.(*pb.TaskListResp)
for _, v := range out.List {
fmt.Printf("%v \n", v)
}
},
// print: func(rsp proto.Message) {
// out := rsp.(*pb.TaskListResp)
// for _, v := range out.List {
// fmt.Printf("%v \n", v)
// }
// },
// enabled: true,
next: func(robot *Robot, rsp proto.Message) {
tcs := []*TestCase{}
if _, ok := rsp.(*pb.TaskListResp); ok {
}
robot.addBuilders(tcs)
},
}, {
desc: "领取任务奖励",
mainType: string(comm.ModuleTask),