Migrate config to mcdsl: Load[T], env overrides, embedded types
Replace local TOML loading with mcdsl/config.Load[Config] which adds METACRYPT_ environment variable overrides. ServerConfig and MCIASConfig now embed their mcdsl counterparts, extending with ExternalURL and ServiceToken respectively. DatabaseConfig and LogConfig replaced with mcdsl types directly. TOML structure is preserved — no config file changes needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,38 @@ server_url = "https://mcias.example.com"
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadEnvOverride(t *testing.T) {
|
||||
content := `
|
||||
[server]
|
||||
listen_addr = ":8443"
|
||||
tls_cert = "cert.pem"
|
||||
tls_key = "key.pem"
|
||||
|
||||
[database]
|
||||
path = "test.db"
|
||||
|
||||
[mcias]
|
||||
server_url = "https://mcias.example.com"
|
||||
`
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "test.toml")
|
||||
_ = os.WriteFile(path, []byte(content), 0600)
|
||||
|
||||
t.Setenv("METACRYPT_SERVER_LISTEN_ADDR", ":9999")
|
||||
t.Setenv("METACRYPT_MCIAS_SERVER_URL", "https://override.example.com")
|
||||
|
||||
cfg, err := Load(path)
|
||||
if err != nil {
|
||||
t.Fatalf("Load: %v", err)
|
||||
}
|
||||
if cfg.Server.ListenAddr != ":9999" {
|
||||
t.Errorf("ListenAddr env override: got %q, want %q", cfg.Server.ListenAddr, ":9999")
|
||||
}
|
||||
if cfg.MCIAS.ServerURL != "https://override.example.com" {
|
||||
t.Errorf("ServerURL env override: got %q", cfg.MCIAS.ServerURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadMissingRequired(t *testing.T) {
|
||||
content := `
|
||||
[server]
|
||||
|
||||
Reference in New Issue
Block a user