保留初始化通知配置并保护新通知凭据
This commit is contained in:
1 parent
efb405ea11
commit
3d1afab22e
7 files changed
+458
-23
No files matched your search
@@ -382,10 +382,11 @@ func (c *Config) Normalize() {
|
||||
if c.Notification.TimeoutSecs == 0 {
|
||||
c.Notification.TimeoutSecs = 10
|
||||
}
|
||||
if c.Notification.RetryCount == 0 {
|
||||
// 空数组表示明确关闭重试,只有旧配置未提供间隔字段时才补默认值。
|
||||
if c.Notification.RetryCount == 0 && c.Notification.RetryIntervalsSecs == nil {
|
||||
c.Notification.RetryCount = 3
|
||||
}
|
||||
if len(c.Notification.RetryIntervalsSecs) == 0 {
|
||||
if c.Notification.RetryIntervalsSecs == nil {
|
||||
c.Notification.RetryIntervalsSecs = []int{30, 120, 600}
|
||||
}
|
||||
if c.Notification.HTTPHeaders == nil {
|
||||
|
||||
@@ -347,3 +347,26 @@ func TestLoadWithEnvRejectsInvalidInteger(t *testing.T) {
|
||||
t.Fatal("无效端口环境变量未被拒绝")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveAndLoadPreservesDisabledNotificationRetries(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
cfg := Default(directory)
|
||||
cfg.Notification.RetryCount = 0
|
||||
cfg.Notification.RetryIntervalsSecs = []int{}
|
||||
path := filepath.Join(directory, "scert.json")
|
||||
if err := cfg.Save(path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := Load(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if loaded.Notification.RetryCount != 0 || len(loaded.Notification.RetryIntervalsSecs) != 0 {
|
||||
t.Fatal("显式关闭通知重试不得在重启时恢复默认重试次数")
|
||||
}
|
||||
cfg.Notification.RetryIntervalsSecs = nil
|
||||
cfg.Normalize()
|
||||
if cfg.Notification.RetryCount != 3 || len(cfg.Notification.RetryIntervalsSecs) != 3 {
|
||||
t.Fatal("缺失通知重试配置的历史配置仍需补齐默认值")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user