优化结构
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user