Files
hfb_jysh/backend/internal/modules/systemconfig/distribution_test.go
T

67 lines
2.3 KiB
Go

package systemconfig
import "testing"
func TestParseDistributionSettlementHoldDays(t *testing.T) {
cases := []struct {
name string
raw string
want int
}{
{name: "零天立即释放", raw: "0", want: 0},
{name: "默认七天", raw: "7", want: 7},
{name: "上限三百六十五天", raw: "365", want: 365},
{name: "负数回落", raw: "-1", want: DefaultDistributionSettlementHoldDays},
{name: "超过上限回落", raw: "366", want: DefaultDistributionSettlementHoldDays},
{name: "空值回落", raw: " ", want: DefaultDistributionSettlementHoldDays},
{name: "非数字回落", raw: "abc", want: DefaultDistributionSettlementHoldDays},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := ParseDistributionSettlementHoldDays(tc.raw); got != tc.want {
t.Fatalf("ParseDistributionSettlementHoldDays(%q) = %d, want %d", tc.raw, got, tc.want)
}
})
}
}
func TestDistributionSettlementHoldDaysConfigRegistered(t *testing.T) {
value := ""
for _, item := range defaultConfigs {
if item.Key == DistributionSettlementHoldDaysKey {
value = item.Value
break
}
}
if value != defaultDistributionSettlementHoldDaysValue() {
t.Fatalf("defaultConfigs 中 %s 的默认值 = %q, want %q", DistributionSettlementHoldDaysKey, value, defaultDistributionSettlementHoldDaysValue())
}
visible := false
for _, key := range adminVisibleConfigKeys {
if key == DistributionSettlementHoldDaysKey {
visible = true
break
}
}
if !visible {
t.Fatalf("adminVisibleConfigKeys 缺少 %s", DistributionSettlementHoldDaysKey)
}
}
func TestValidateConfigValueDistributionSettlementHoldDays(t *testing.T) {
for _, value := range []string{"0", "7", "365"} {
if err := validateConfigValue(DistributionSettlementHoldDaysKey, value); err != nil {
t.Fatalf("validateConfigValue(%q) = %v, want nil", value, err)
}
}
for _, value := range []string{"-1", "366", "", "abc"} {
if err := validateConfigValue(DistributionSettlementHoldDaysKey, value); err != ErrInvalidConfig {
t.Fatalf("validateConfigValue(%q) = %v, want ErrInvalidConfig", value, err)
}
}
// 未注册校验的键直接放行。
if err := validateConfigValue("handoff.owner_submit_timeout_minutes", "abc"); err != nil {
t.Fatalf("无关配置键应放行, got %v", err)
}
}