refactor(config): 统一共享配置模板来源

This commit is contained in:
2026-09-19 08:00:55 +08:00
parent 56ad014199
commit e6622b32c7
7 changed files with 141 additions and 186 deletions
+19
View File
@@ -27,12 +27,31 @@ func TestLoadConfigFromBinaryDirFirstLaunchCreatesExampleOnly(t *testing.T) {
if _, err := os.Stat(filepath.Join(dir, ConfigExampleName)); err != nil {
t.Fatalf("config.toml.example was not created: %v", err)
}
examplePath := filepath.Join(dir, ConfigExampleName)
example, err := os.ReadFile(examplePath)
if err != nil {
t.Fatal(err)
}
if string(example) != ConfigTOMLTemplate {
t.Fatal("first-launch example differs from the canonical runtime template")
}
if _, err := os.Stat(filepath.Join(dir, ".env")); !os.IsNotExist(err) {
t.Fatalf("unexpected .env after first launch, err=%v", err)
}
if cfg.Listen != DefaultListen || cfg.RPCTimeout != 30*time.Second {
t.Fatalf("first launch changed defaults: %+v", cfg)
}
if err := LoadConfigFromBinaryDir(dir, &cfg); err != nil {
t.Fatal(err)
}
unchanged, err := os.ReadFile(examplePath)
if err != nil {
t.Fatal(err)
}
if string(unchanged) != string(example) {
t.Fatal("existing config.toml.example was modified")
}
}
func TestCheckedInBatAPIConfigExampleMatchesRuntimeTemplate(t *testing.T) {