75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package robot
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/modules/user"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/Pallinder/go-randomdata"
|
|
jsoniter "github.com/json-iterator/go"
|
|
"github.com/nacos-group/nacos-sdk-go/util"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type LoginParam struct {
|
|
Account string `json:"account"`
|
|
ServerId int32 `json:"serverId"`
|
|
TimeStamp int64 `json:"timestamp"`
|
|
}
|
|
|
|
func (r *Robot) BuildSecStr() string {
|
|
jsonByte, _ := jsoniter.Marshal(&LoginParam{
|
|
Account: r.opts.Account,
|
|
ServerId: r.opts.ServerId,
|
|
TimeStamp: time.Now().Unix(),
|
|
})
|
|
jsonBase64 := utils.Base64Encode(jsonByte)
|
|
// log.Printf("client base64:%s", jsonBase64)
|
|
clientMd5key := util.Md5(jsonBase64)
|
|
// log.Printf("client md5:%s", clientMd5key)
|
|
return fmt.Sprintf("CE:%s%s", clientMd5key, jsonBase64)
|
|
}
|
|
|
|
//处理登录请求
|
|
func (r *Robot) AccountLogin() {
|
|
log.Printf("区服:[%d] 账号:[%s] login...", r.opts.ServerId, r.opts.Account)
|
|
builders := []*TestCase{
|
|
{
|
|
id: "login",
|
|
desc: "登录",
|
|
mainType: string(comm.ModuleUser),
|
|
subType: user.UserSubTypeLogin,
|
|
req: &pb.UserLoginReq{
|
|
Account: r.opts.Account,
|
|
Sid: r.opts.ServerId,
|
|
},
|
|
rsp: &pb.UserLoginResp{},
|
|
enabled: true,
|
|
next: func(r *Robot, rsp proto.Message) {
|
|
tcs := []*TestCase{}
|
|
if _, ok := rsp.(*pb.UserLoginResp); ok {
|
|
nick := randomdata.SillyName()
|
|
tc := &TestCase{
|
|
desc: "创角",
|
|
mainType: string(comm.ModuleUser),
|
|
subType: user.UserSubTypeCreate,
|
|
req: &pb.UserCreateReq{ //设置请求参数
|
|
NickName: nick,
|
|
},
|
|
rsp: &pb.UserCreateResp{},
|
|
// enabled: true,
|
|
}
|
|
tcs = append(tcs, tc)
|
|
r.addBuilders(tcs)
|
|
}
|
|
|
|
},
|
|
},
|
|
}
|
|
r.addTestCaseAndReq(builders)
|
|
}
|