Files
hi-server/pkg/xerr/errMsg_test.go
T
架构师 54379976ec
Build docker and publish / build (20.15.1) (push) Failing after 20m57s
Build docker and publish / build (20.15.1) (pull_request) Failing after 19m44s
修复(#138): 补齐 errMsg 漏掉的错误码映射
新增 UserCommissionNotEnough、SendSmsError、AreaCodeIsEmpty、
DeviceBindLimitExceeded、ExistAvailableTraffic 五个错误码的中文映射,
修复管理后台审批提现等接口业务校验失败时 msg 被误显为
"Internal Server Error" 的问题。

Co-authored-by: multica-agent <github@multica.ai>
2026-06-01 22:29:36 -07:00

46 lines
1.5 KiB
Go

package xerr
import "testing"
// TestMapErrMsg_MissingCodesAreFilled 覆盖 HIF-138 中补齐的 5 个错误码:
// 这些码之前在 message 表中缺失,导致 MapErrMsg 回退到 "Internal Server Error"。
func TestMapErrMsg_MissingCodesAreFilled(t *testing.T) {
cases := []struct {
name string
code uint32
want string
}{
{"UserCommissionNotEnough", UserCommissionNotEnough, "佣金余额不足"},
{"SendSmsError", SendSmsError, "短信发送失败"},
{"AreaCodeIsEmpty", AreaCodeIsEmpty, "国家区号不能为空"},
{"DeviceBindLimitExceeded", DeviceBindLimitExceeded, "设备绑定数量已达上限"},
{"ExistAvailableTraffic", ExistAvailableTraffic, "存在可用流量"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := MapErrMsg(tc.code)
if got == "Internal Server Error" {
t.Fatalf("MapErrMsg(%d) fell back to Internal Server Error; expected %q", tc.code, tc.want)
}
if got != tc.want {
t.Errorf("MapErrMsg(%d) = %q, want %q", tc.code, got, tc.want)
}
if !IsCodeErr(tc.code) {
t.Errorf("IsCodeErr(%d) = false, want true", tc.code)
}
})
}
}
// TestMapErrMsg_UnknownCodeFallsBack 验证未定义码仍然安全回退,不 panic。
func TestMapErrMsg_UnknownCodeFallsBack(t *testing.T) {
const unknown uint32 = 99999
if got := MapErrMsg(unknown); got != "Internal Server Error" {
t.Errorf("MapErrMsg(%d) = %q, want %q", unknown, got, "Internal Server Error")
}
if IsCodeErr(unknown) {
t.Errorf("IsCodeErr(%d) = true, want false", unknown)
}
}