feat(game/activity_vip_user_new):封装官网白名单、黑名单用户获取
This commit is contained in:
parent
a34bb1c45e
commit
4c4cebea5d
27
README.md
27
README.md
@ -177,3 +177,30 @@ func CreateDemoTestResponse() *DemoTestResponse {
|
||||
```
|
||||
DEBUG=sdk,signer,request
|
||||
```
|
||||
|
||||
### 5.测试用例编写要求
|
||||
|
||||
新增或修改 `services/*` 下的接口封装时,**必须**配套可编译的测试,并遵循下列约定(风格可参考 `services/cs/client_test.go` 与 `services/game/client_test.go`)。
|
||||
|
||||
#### 5.1 单测职责(一条用例里要覆盖什么)
|
||||
|
||||
- **请求侧**:构造 `Create*Request`,填入业务参数后调用 `requests.InitParam(req)`,再断言 HTTP 方法、`GetActionName()` 路径、以及 Query/Form 等关键参数是否注入正确。
|
||||
- **调用侧**:使用本服务 `NewClient()`(或项目约定的构造方式)**真实调用** `Client` 上对应方法,覆盖 `DoAction` 与签名、序列化整条链路。
|
||||
- **响应侧**:断言 `err == nil`、响应非 `nil`,并对业务字段做断言(如 `Code`、`Msg`、`Data` 及关键业务 ID、类型等);**必须**通过 `fmt.Printf` 打印返回内容,便于人工核对逻辑是否正确。
|
||||
- **风格**:与 `cs` 一致时优先使用 `t.Error` / `t.Errorf` + `return` 早退出;断言失败时除 `t.Errorf` 外可再 `fmt.Printf("%#+v\n", resp)`(及对 `*resp.Data`)便于排错。
|
||||
|
||||
#### 5.2 组织方式
|
||||
|
||||
- **同一能力的多条场景**(如白名单与黑名单):可拆成 `TestXxx`、`TestXxxBlack` 等若干函数,**每个函数内**仍应完整包含「请求校验 → 真实调用 → 响应断言 → 打印」,避免把断言拆成大量只测一行的小函数。
|
||||
- **禁止**仅写「只校验 `InitParam`、不调 Client」的孤立用例作为唯一测试;若需 mock(无网/CI),可另加辅助函数,但不应替代上述真实调用用例作为唯一验收。
|
||||
|
||||
#### 5.3 输出与可读性
|
||||
|
||||
- 使用 `fmt.Printf("%#+v\n", resp)` 打印完整响应结构体;若 `Data` 为指针,再打印 `fmt.Printf("%#+v\n", *resp.Data)`。
|
||||
- 测试函数顶部用简短中文注释说明测的是哪条接口、什么场景。
|
||||
|
||||
#### 5.4 运行
|
||||
|
||||
```bash
|
||||
go test ./services/<包名> -run Test<名称> -v
|
||||
```
|
||||
55
services/game/activity_vip_user_new.go
Normal file
55
services/game/activity_vip_user_new.go
Normal file
@ -0,0 +1,55 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
||||
)
|
||||
|
||||
type GetActivityVipUserNewWhitelistReq struct {
|
||||
*requests.RpcRequest
|
||||
UserName string `position:"Body" field:"user_name" default:""`
|
||||
}
|
||||
|
||||
type GetActivityVipUserNewBlacklistReq struct {
|
||||
*requests.RpcRequest
|
||||
UserName string `position:"Body" field:"user_name" default:""`
|
||||
}
|
||||
|
||||
type ActivityVipUserNewInfo struct {
|
||||
Id int64 `json:"id"`
|
||||
UserName string `json:"user_name"`
|
||||
UserType int `json:"user_type"`
|
||||
}
|
||||
|
||||
type GetActivityVipUserNewResp struct {
|
||||
*responses.BaseResponse
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data *ActivityVipUserNewInfo `json:"data"`
|
||||
}
|
||||
|
||||
func CreateGetActivityVipUserNewWhitelistReq(userName string) *GetActivityVipUserNewWhitelistReq {
|
||||
req := &GetActivityVipUserNewWhitelistReq{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
}
|
||||
req.UserName = userName
|
||||
req.InitWithApiInfo(HOST, VERSION, "/api/login/getActivityVipUserNewWhitelist")
|
||||
req.Method = requests.POST
|
||||
return req
|
||||
}
|
||||
|
||||
func CreateGetActivityVipUserNewBlacklistReq(userName string) *GetActivityVipUserNewBlacklistReq {
|
||||
req := &GetActivityVipUserNewBlacklistReq{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
}
|
||||
req.UserName = userName
|
||||
req.InitWithApiInfo(HOST, VERSION, "/api/login/getActivityVipUserNewBlacklist")
|
||||
req.Method = requests.POST
|
||||
return req
|
||||
}
|
||||
|
||||
func CreateGetActivityVipUserNewResp() *GetActivityVipUserNewResp {
|
||||
return &GetActivityVipUserNewResp{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
}
|
||||
@ -49,6 +49,20 @@ func (c *Client) GetLoginInfoById(req *GetLoginInfoByIdReq) (resp *GetLoginInfoB
|
||||
return
|
||||
}
|
||||
|
||||
// GetActivityVipUserNewWhitelist 获取活动 VIP 白名单用户
|
||||
func (c *Client) GetActivityVipUserNewWhitelist(req *GetActivityVipUserNewWhitelistReq) (resp *GetActivityVipUserNewResp, err error) {
|
||||
resp = CreateGetActivityVipUserNewResp()
|
||||
err = c.DoAction(req, resp)
|
||||
return
|
||||
}
|
||||
|
||||
// GetActivityVipUserNewBlacklist 获取活动 VIP 黑名单用户
|
||||
func (c *Client) GetActivityVipUserNewBlacklist(req *GetActivityVipUserNewBlacklistReq) (resp *GetActivityVipUserNewResp, err error) {
|
||||
resp = CreateGetActivityVipUserNewResp()
|
||||
err = c.DoAction(req, resp)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) GetProtocolByGameId(req *GetProtocolByGameIdRep) (resp *GetProtocolByGameIdResp, err error) {
|
||||
resp = CreateGetProtocolByGameIdResp()
|
||||
err = c.DoAction(req, resp)
|
||||
|
||||
@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||
)
|
||||
|
||||
func TestGetGameOsInfo(t *testing.T) {
|
||||
@ -301,3 +303,83 @@ func TestGetGameListExtInfo(t *testing.T) {
|
||||
fmt.Println(gameListExtInfo.Status, gameListExtInfo.Code, gameListExtInfo.Msg)
|
||||
fmt.Printf("%+v\n", gameListExtInfo.Data)
|
||||
}
|
||||
|
||||
func TestGetActivityVipUserNewWhitelist(t *testing.T) {
|
||||
req := CreateGetActivityVipUserNewWhitelistReq("lmw888")
|
||||
if err := requests.InitParam(req); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if req.GetMethod() != requests.POST || req.GetActionName() != "/api/login/getActivityVipUserNewWhitelist" {
|
||||
t.Errorf("whitelist req: method=%s path=%s", req.GetMethod(), req.GetActionName())
|
||||
return
|
||||
}
|
||||
if req.GetFormParams()["user_name"] != "lmw888" {
|
||||
t.Errorf("whitelist user_name: %q", req.GetFormParams()["user_name"])
|
||||
return
|
||||
}
|
||||
|
||||
client, err := NewClient()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
resp, err := client.GetActivityVipUserNewWhitelist(req)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if resp == nil {
|
||||
t.Errorf("whitelist response is nil")
|
||||
return
|
||||
}
|
||||
if resp.Code != 0 || resp.Msg != "获取成功" || resp.Data == nil || resp.Data.UserType != 1 {
|
||||
t.Errorf("whitelist response: code=%d msg=%s data=%+v", resp.Code, resp.Msg, resp.Data)
|
||||
fmt.Printf("%#+v\n", resp)
|
||||
return
|
||||
}
|
||||
fmt.Printf("%#+v\n", resp)
|
||||
if resp.Data != nil {
|
||||
fmt.Printf("%#+v\n", *resp.Data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetActivityVipUserNewBlacklist(t *testing.T) {
|
||||
req := CreateGetActivityVipUserNewBlacklistReq("lmw777")
|
||||
if err := requests.InitParam(req); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if req.GetMethod() != requests.POST || req.GetActionName() != "/api/login/getActivityVipUserNewBlacklist" {
|
||||
t.Errorf("blacklist req: method=%s path=%s", req.GetMethod(), req.GetActionName())
|
||||
return
|
||||
}
|
||||
if req.GetFormParams()["user_name"] != "lmw777" {
|
||||
t.Errorf("blacklist user_name: %q", req.GetFormParams()["user_name"])
|
||||
return
|
||||
}
|
||||
|
||||
client, err := NewClient()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
resp, err := client.GetActivityVipUserNewBlacklist(req)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if resp == nil {
|
||||
t.Errorf("blacklist response is nil")
|
||||
return
|
||||
}
|
||||
if resp.Code != 0 || resp.Msg != "获取成功" || resp.Data == nil || resp.Data.UserType != 2 {
|
||||
t.Errorf("blacklist response: code=%d msg=%s data=%+v", resp.Code, resp.Msg, resp.Data)
|
||||
fmt.Printf("%#+v\n", resp)
|
||||
return
|
||||
}
|
||||
fmt.Printf("%#+v\n", resp)
|
||||
if resp.Data != nil {
|
||||
fmt.Printf("%#+v\n", *resp.Data)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user