Files
junhong_cmp_fiber/internal/task/polling_cardstatus_handler_test.go
break 5c2ef97c24
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m57s
相关问题优化以及新功能开发
迁移 155- 157
2026-06-22 17:21:13 +09:00

64 lines
1.6 KiB
Go

package task
import (
"testing"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/pkg/constants"
)
// TestShouldStopPolling 验证风险状态独立卡的轮询停止判断逻辑
func TestShouldStopPolling(t *testing.T) {
cases := []struct {
name string
isStandalone bool
gatewayExtend string
want bool
}{
{
name: "独立卡+风险停机 -> 停止轮询",
isStandalone: true,
gatewayExtend: constants.GatewayCardExtendRiskStop,
want: true,
},
{
name: "独立卡+已销户 -> 停止轮询",
isStandalone: true,
gatewayExtend: constants.GatewayCardExtendCancelled,
want: true,
},
{
name: "非独立卡+风险停机 -> 不停止轮询",
isStandalone: false,
gatewayExtend: constants.GatewayCardExtendRiskStop,
want: false,
},
{
name: "独立卡+机卡分离停机 -> 不停止轮询",
isStandalone: true,
gatewayExtend: constants.GatewayCardExtendMachineSeparated,
want: false,
},
{
name: "独立卡+空扩展 -> 不停止轮询",
isStandalone: true,
gatewayExtend: "",
want: false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
card := &model.IotCard{
IsStandalone: tc.isStandalone,
GatewayExtend: tc.gatewayExtend,
}
got := shouldStopPollingForRisk(card, tc.gatewayExtend)
if got != tc.want {
t.Errorf("shouldStopPollingForRisk(standalone=%v, extend=%q) = %v, 期望 %v",
tc.isStandalone, tc.gatewayExtend, got, tc.want)
}
})
}
}