Includes the current working directory changes. Historical commits and release binaries are excluded to limit Gitea storage. Source base: d7515973fbfd6dd2001fa156c483455b8081c7cb
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package config
|
||
|
||
import (
|
||
"os"
|
||
"path/filepath"
|
||
"testing"
|
||
)
|
||
|
||
// 验证用户配置 YAML 往返:Save 后 Load 得到一致的归一化字段,
|
||
// 特别是 *bool(persistentMode)与新增的 refreshIntervalSeconds。
|
||
func TestConfigRoundTrip(t *testing.T) {
|
||
path := filepath.Join(t.TempDir(), "config.yaml")
|
||
store := NewStore(path, "")
|
||
|
||
input := DefaultConfig()
|
||
input.HomeMetrics.IncludeCacheWriteInHitRate = true
|
||
input.HomeMetrics.RefreshIntervalSeconds = 30
|
||
input.HomeMetrics.PersistentMode = boolPtr(false)
|
||
input.Routing.Mode = "local"
|
||
input.ModelAdapters = []ModelAdapterConfig{} // Normalize 会补默认值
|
||
|
||
if _, err := store.Save(nil, input); err != nil {
|
||
t.Fatalf("save: %v", err)
|
||
}
|
||
|
||
loaded, err := store.Load(nil)
|
||
if err != nil {
|
||
t.Fatalf("load: %v", err)
|
||
}
|
||
|
||
if loaded.HomeMetrics.IncludeCacheWriteInHitRate != true {
|
||
t.Error("includeCacheWriteInHitRate round-trip mismatch")
|
||
}
|
||
if loaded.HomeMetrics.RefreshIntervalSeconds != 30 {
|
||
t.Errorf("refreshIntervalSeconds = %d, want 30", loaded.HomeMetrics.RefreshIntervalSeconds)
|
||
}
|
||
if loaded.HomeMetrics.PersistentMode == nil || *loaded.HomeMetrics.PersistentMode != false {
|
||
t.Error("persistentMode round-trip mismatch: want false")
|
||
}
|
||
if loaded.Routing.Mode != "local" {
|
||
t.Errorf("routing.mode = %q, want local", loaded.Routing.Mode)
|
||
}
|
||
|
||
// 幂等:二次保存后再读仍一致。
|
||
if _, err := store.Save(nil, loaded); err != nil {
|
||
t.Fatalf("resave: %v", err)
|
||
}
|
||
reloaded, err := store.Load(nil)
|
||
if err != nil {
|
||
t.Fatalf("reload: %v", err)
|
||
}
|
||
if reloaded.HomeMetrics.RefreshIntervalSeconds != 30 {
|
||
t.Errorf("second load refreshIntervalSeconds = %d, want 30", reloaded.HomeMetrics.RefreshIntervalSeconds)
|
||
}
|
||
if _, err := os.Stat(path); err != nil {
|
||
t.Fatalf("config file missing: %v", err)
|
||
}
|
||
}
|