From 8b692dd9afd337e5b8436d2a51c4a3d6cdc8535a Mon Sep 17 00:00:00 2001 From: xuyang Date: Wed, 5 Aug 2026 11:41:40 +0800 Subject: [PATCH] =?UTF-8?q?test(game):=20=E8=A1=A5=E5=85=85=20GetKfUrl=20?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=8F=82=E6=95=B0=E7=9B=B4=E6=8E=A5=E6=96=AD?= =?UTF-8?q?=E8=A8=80=EF=BC=8C=E9=AA=8C=E8=AF=81=20uid=20=E7=A9=BA=E5=80=BC?= =?UTF-8?q?=E4=B8=8D=E4=B8=8B=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/game/kf_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/services/game/kf_test.go b/services/game/kf_test.go index f18a23d..96df1cc 100644 --- a/services/game/kf_test.go +++ b/services/game/kf_test.go @@ -4,6 +4,8 @@ import ( "fmt" "strings" "testing" + + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" ) func TestGetKfUrl(t *testing.T) { @@ -57,3 +59,26 @@ func TestGetKfUrlGuest(t *testing.T) { } fmt.Println(resp.Code, resp.Msg, resp.Data.KfUrl) } + +// TestGetKfUrlReqParams 直接断言请求参数:不设 Uid 时 JsonParams 里不应出现 "uid" key, +// 设了 Uid 时应正确出现,避免只靠服务端返回的 kf_url 做间接验证。 +func TestGetKfUrlReqParams(t *testing.T) { + guestReq := CreateGetKfUrlReq() + guestReq.GameId = 10003 + if err := requests.InitParam(guestReq); err != nil { + t.Fatalf("InitParam err: %v", err) + } + if _, ok := guestReq.JsonParams["uid"]; ok { + t.Fatalf("游客请求不应包含 uid 参数: %v", guestReq.JsonParams["uid"]) + } + + userReq := CreateGetKfUrlReq() + userReq.GameId = 10001 + userReq.Uid = "166146" + if err := requests.InitParam(userReq); err != nil { + t.Fatalf("InitParam err: %v", err) + } + if userReq.JsonParams["uid"] != "166146" { + t.Fatalf("expect uid=166146, got %v", userReq.JsonParams["uid"]) + } +}