优化结构

This commit is contained in:
Yvan
2026-08-28 09:19:54 +08:00
parent 03a4131f6e
commit 279692375b
57 changed files with 778 additions and 799 deletions
+23
View File
@@ -145,3 +145,26 @@ func TestStoreWatchPreservesDatabaseBackedIntegrationSettings(t *testing.T) {
}
t.Fatal("watcher did not publish the changed file")
}
func TestMergeRuntimeConfigPreservesOmittedSections(t *testing.T) {
current := &Config{
Server: &Server{HTTP: &ServerHTTP{Addr: ":8080"}},
Data: &Data{Database: &Database{Source: "current-dsn"}},
Admin: &Admin{ConfigPath: "config.yaml", Storage: &Storage{Type: "local"}, Email: &Email{Host: "smtp.example.com"}},
}
next := &Config{Admin: &Admin{App: &App{AppID: "next"}}}
merged := MergeRuntimeConfig(current, next)
if merged.Server == nil || merged.Server.HTTP == nil || merged.Server.HTTP.Addr != ":8080" {
t.Fatalf("server was not preserved: %#v", merged.Server)
}
if merged.Data == nil || merged.Data.Database == nil || merged.Data.Database.Source != "current-dsn" {
t.Fatalf("data was not preserved: %#v", merged.Data)
}
if merged.Admin.Storage == nil || merged.Admin.Storage.Type != "local" || merged.Admin.Email == nil || merged.Admin.Email.Host != "smtp.example.com" {
t.Fatalf("integration settings were not preserved: %#v", merged.Admin)
}
merged.Admin.Storage.Type = "changed"
if current.Admin.Storage.Type != "local" {
t.Fatal("MergeRuntimeConfig leaked mutable storage state into current config")
}
}