优化结构

This commit is contained in:
Yvan
2026-08-24 17:03:46 +08:00
parent acaee94858
commit 7643152c1e
15 changed files with 244 additions and 203 deletions
+29
View File
@@ -116,3 +116,32 @@ func TestStoreWatchReloadAndClose(t *testing.T) {
}
t.Fatalf("watcher did not reload configuration: %#v", store.Snapshot())
}
func TestStoreWatchPreservesDatabaseBackedIntegrationSettings(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "config.yaml")
writeConfig(t, path, "data: {}\nadmin: {}\n")
store, err := LoadStore(path)
if err != nil {
t.Fatal(err)
}
defer store.Close()
current := store.Snapshot()
current.Admin.Storage = &Storage{Type: "local"}
current.Admin.Email = &Email{Host: "smtp.example.com"}
store.Replace(current)
writeConfig(t, path, "data:\n redis:\n addr: 127.0.0.1:6379\nadmin: {}\n")
deadline := time.Now().Add(3 * time.Second)
for time.Now().Before(deadline) {
value := store.Snapshot()
if value != nil && value.Data != nil && value.Data.Redis != nil && value.Data.Redis.Addr != "" {
if value.Admin == nil || value.Admin.Storage == nil || value.Admin.Storage.Type != "local" || value.Admin.Email == nil || value.Admin.Email.Host != "smtp.example.com" {
t.Fatalf("database-backed settings were lost: %#v", value.Admin)
}
return
}
time.Sleep(20 * time.Millisecond)
}
t.Fatal("watcher did not publish the changed file")
}