f-46: config: fail loudly on an unreadable config file #46

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-09-09 21:57:51 +02:00
commit a220cce77e
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
2 changed files with 33 additions and 1 deletions

View file

@ -54,3 +54,29 @@ func TestLoadConfig_ReadsTheTwoBackend(t *testing.T) {
t.Errorf("backend = %q, want two", cfg.DHCP.Backend)
}
}
func TestLoadConfig_MalformedFileIsReported(t *testing.T) {
path := writeConfig(t, "--\n\ndhcp:\n backend: two\n")
if _, err := LoadConfig(path); err == nil {
t.Fatal("an unparseable config must be reported: silently falling back to defaults would run the wrong dhcp backend")
}
}
func TestLoadConfig_TabIndentedFileIsReported(t *testing.T) {
path := writeConfig(t, "dhcp:\n\tbackend: two\n")
if _, err := LoadConfig(path); err == nil {
t.Fatal("yaml forbids tabs for indentation: that must surface, not be swallowed")
}
}
func TestLoadConfig_MissingFileStillFallsBackToDefaults(t *testing.T) {
cfg, err := LoadConfig(filepath.Join(t.TempDir(), "absent.yml"))
if err != nil {
t.Fatalf("an absent file remains valid, only an unreadable one is an error: %v", err)
}
if cfg.DHCP.Backend != BackendDnsmasq {
t.Errorf("backend = %q, want %q", cfg.DHCP.Backend, BackendDnsmasq)
}
}