新建站点的默认冷却期原先硬编码 7 天(OnboardSite 字面量、DB 列默认、两套前端表单), 改一处要同时动三处。现统一到系统配置键 distribution.default_settlement_hold_days: - systemconfig 注册该键(默认 7,0=立即释放,0-365 校验),纳入 admin 可见配置 - distribution 建站两条路径(CreateSite 未传值、OnboardSite 缺省)读取该配置,缺失或非法回落 7 - 新增 GET /admin/distribution/site-defaults 暴露当前有效默认值 - Vue / React 站点表单改为运行时拉取,拉取失败保持 7 - DB 列默认值保留作为兜底,站点级 settlement_hold_days 仍可单独覆盖
67 lines
2.3 KiB
Go
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)
|
|
}
|
|
}
|