From 813ff63153247a5b6844421d0f7975e49cc52868 Mon Sep 17 00:00:00 2001 From: sneak Date: Fri, 7 Aug 2026 17:02:44 +0000 Subject: [PATCH] test: explicitly empty db_url must abort startup (PR #53 rework) db_url: "" currently silently derives the state_dir-based sqlite URL, which is a default applied to a SET value; state_dir: "" already aborts. Failing test first, fix follows. --- internal/config/config_validation_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/internal/config/config_validation_test.go b/internal/config/config_validation_test.go index f1a58f6..c5dbc92 100644 --- a/internal/config/config_validation_test.go +++ b/internal/config/config_validation_test.go @@ -395,6 +395,25 @@ func TestExplicitNullValueAbortsStartup(t *testing.T) { } } +// TestExplicitlyEmptyDBURLAbortsStartup verifies that db_url set to an +// empty string aborts startup: the derived file:...state.sqlite3 URL is +// a default, and defaults apply only to omitted keys. This matches +// state_dir, where an explicitly empty value already aborts. +func TestExplicitlyEmptyDBURLAbortsStartup(t *testing.T) { + yamlContent := "signing_key: " + validTestSigningKey + "\ndb_url: \"\"\n" + + c, err := configFromYAML(t, yamlContent) + if err == nil { + t.Fatalf("explicitly empty db_url must abort startup, got config: %+v", c) + } + + t.Logf("got expected error: %v", err) + + if !strings.Contains(err.Error(), "db_url") { + t.Errorf("error %q does not name the offending key db_url", err.Error()) + } +} + func TestUnknownTopLevelKeyAbortsStartup(t *testing.T) { yamlContent := `signing_key: ` + validTestSigningKey + ` whitelist_hosts: