6
0

Merge branch 'develop/chj/dms-ip-device-filter' of https://golib.gaore.com/GaoreGo/gaore-common-sdk-go into develop/chj/dms-ip-device-filter

This commit is contained in:
陈华健 2026-07-03 16:10:10 +08:00
commit 43d5759668

View File

@ -0,0 +1,38 @@
package big_data
import (
"encoding/json"
"io"
"testing"
)
// TestGetBodyReaderCarriesIPAndDeviceID 验证 ip / device_id 能被序列化进发往大数据的请求体。
// 这两个字段此前在 SDK 里缺失,导致前端传的 IP/设备号被静默丢弃。
func TestGetBodyReaderCarriesIPAndDeviceID(t *testing.T) {
req := CreateGetUserProfileRequest("token-x", GetUserProfileParam{
IP: []string{"59.51.36.195"},
DeviceId: []string{"dev-abc", "dev-def"},
Page: 1,
PageSize: 50,
})
raw, err := io.ReadAll(req.GetBodyReader())
if err != nil {
t.Fatalf("读取 body 失败: %v", err)
}
var body struct {
IP []string `json:"ip"`
DeviceId []string `json:"device_id"`
}
if err := json.Unmarshal(raw, &body); err != nil {
t.Fatalf("反序列化 body 失败: %v, 原始=%s", err, raw)
}
if len(body.IP) != 1 || body.IP[0] != "59.51.36.195" {
t.Errorf("ip 未正确透传, 期望 [59.51.36.195], 实际 %v, 原始=%s", body.IP, raw)
}
if len(body.DeviceId) != 2 || body.DeviceId[0] != "dev-abc" || body.DeviceId[1] != "dev-def" {
t.Errorf("device_id 未正确透传, 期望 [dev-abc dev-def], 实际 %v, 原始=%s", body.DeviceId, raw)
}
}