Compare commits
No commits in common. "50304376dc26f7eb0a24da4421f3da41e4f13749" and "a34bb1c45e294a68027e4cd4e0afe933ad9c3698" have entirely different histories.
50304376dc
...
a34bb1c45e
27
README.md
27
README.md
@ -176,31 +176,4 @@ func CreateDemoTestResponse() *DemoTestResponse {
|
|||||||
终端调试打开方式, 需要在系统环境变量上加入(三选一):
|
终端调试打开方式, 需要在系统环境变量上加入(三选一):
|
||||||
```
|
```
|
||||||
DEBUG=sdk,signer,request
|
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
|
|
||||||
```
|
```
|
||||||
@ -1,55 +0,0 @@
|
|||||||
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,20 +49,6 @@ func (c *Client) GetLoginInfoById(req *GetLoginInfoByIdReq) (resp *GetLoginInfoB
|
|||||||
return
|
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) {
|
func (c *Client) GetProtocolByGameId(req *GetProtocolByGameIdRep) (resp *GetProtocolByGameIdResp, err error) {
|
||||||
resp = CreateGetProtocolByGameIdResp()
|
resp = CreateGetProtocolByGameIdResp()
|
||||||
err = c.DoAction(req, resp)
|
err = c.DoAction(req, resp)
|
||||||
|
|||||||
@ -4,8 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetGameOsInfo(t *testing.T) {
|
func TestGetGameOsInfo(t *testing.T) {
|
||||||
@ -303,83 +301,3 @@ func TestGetGameListExtInfo(t *testing.T) {
|
|||||||
fmt.Println(gameListExtInfo.Status, gameListExtInfo.Code, gameListExtInfo.Msg)
|
fmt.Println(gameListExtInfo.Status, gameListExtInfo.Code, gameListExtInfo.Msg)
|
||||||
fmt.Printf("%+v\n", gameListExtInfo.Data)
|
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 != 1 || 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 != 1 || 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -87,11 +87,3 @@ func (c *Client) GetUserLabels(req *GetUserLabelsRequest) (response *GetUserLabe
|
|||||||
err = c.DoAction(req, response)
|
err = c.DoAction(req, response)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserRegInfo
|
|
||||||
// 获取用户注册信息
|
|
||||||
func (c *Client) GetUserRegInfo(req *GetUserRegInfoRequest) (response *GetUserRegInfoResponse, err error) {
|
|
||||||
response = CreateGetUserRegInfoResponse()
|
|
||||||
err = c.DoAction(req, response)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
package passport
|
package passport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 单元测试
|
// 单元测试
|
||||||
@ -112,58 +109,3 @@ func TestUpdateUserState(t *testing.T) {
|
|||||||
// 记录文本结果
|
// 记录文本结果
|
||||||
t.Logf("resp code:%+v, msg:%s", resp.Code, resp.Msg)
|
t.Logf("resp code:%+v, msg:%s", resp.Code, resp.Msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 测试获取用户注册信息
|
|
||||||
func TestGetUserRegInfo(t *testing.T) {
|
|
||||||
req := CreateGetUserRegInfoRequest("xc21225964")
|
|
||||||
if err := requests.InitParam(req); err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.GetMethod() != requests.POST || req.GetActionName() != "/remote_login.php" {
|
|
||||||
t.Errorf("get user reg info req: method=%s path=%s", req.GetMethod(), req.GetActionName())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.GetFormParams()["act"] != "info" {
|
|
||||||
t.Errorf("unexpected act param: %q", req.GetFormParams()["act"])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.GetFormParams()["do"] != "get_user_reg_info" {
|
|
||||||
t.Errorf("unexpected do param: %q", req.GetFormParams()["do"])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.GetFormParams()["user_name"] != "xc21225964" {
|
|
||||||
t.Errorf("unexpected user_name param: %q", req.GetFormParams()["user_name"])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.GetFormParams()["time"] == "" || req.GetFormParams()["sign"] == "" {
|
|
||||||
t.Errorf("unexpected sign params: time=%q sign=%q", req.GetFormParams()["time"], req.GetFormParams()["sign"])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := NewClient()
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
resp, err := client.GetUserRegInfo(req)
|
|
||||||
if err != nil {
|
|
||||||
if resp != nil {
|
|
||||||
fmt.Printf("%s\n", resp.GetHttpContentString())
|
|
||||||
fmt.Printf("%#+v\n", resp)
|
|
||||||
}
|
|
||||||
t.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if resp == nil {
|
|
||||||
t.Errorf("get user reg info response is nil")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if resp.Code != 1 || resp.Msg != "获取成功" || resp.Data.RegTime <= 0 {
|
|
||||||
t.Errorf("get user reg info response: code=%d msg=%s data=%+v", resp.Code, resp.Msg, resp.Data)
|
|
||||||
fmt.Printf("%#+v\n", resp)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("%#+v\n", resp)
|
|
||||||
fmt.Printf("%#+v\n", resp.Data)
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,46 +0,0 @@
|
|||||||
package passport
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
|
||||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
|
||||||
)
|
|
||||||
|
|
||||||
type GetUserRegInfoRequest struct {
|
|
||||||
*requests.RpcRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetUserRegInfoResponse struct {
|
|
||||||
*responses.BaseResponse
|
|
||||||
Code int `json:"code"`
|
|
||||||
Msg string `json:"msg"`
|
|
||||||
Data struct {
|
|
||||||
RegTime int64 `json:"reg_time"`
|
|
||||||
GameId int64 `json:"game_id"`
|
|
||||||
} `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateGetUserRegInfoRequest 获取用户注册信息
|
|
||||||
func CreateGetUserRegInfoRequest(userName string) (req *GetUserRegInfoRequest) {
|
|
||||||
ts, sign := GetSign()
|
|
||||||
req = &GetUserRegInfoRequest{
|
|
||||||
RpcRequest: &requests.RpcRequest{},
|
|
||||||
}
|
|
||||||
req.InitWithApiInfo(HOST, VERSION, "/remote_login.php")
|
|
||||||
req.FormParams = map[string]string{
|
|
||||||
"act": "info",
|
|
||||||
"do": "get_user_reg_info",
|
|
||||||
"user_name": userName,
|
|
||||||
"time": fmt.Sprintf("%v", ts),
|
|
||||||
"sign": sign,
|
|
||||||
}
|
|
||||||
req.Method = requests.POST
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateGetUserRegInfoResponse() (response *GetUserRegInfoResponse) {
|
|
||||||
response = &GetUserRegInfoResponse{
|
|
||||||
BaseResponse: &responses.BaseResponse{},
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user