diff --git a/internal/config/config_validation_internal_test.go b/internal/config/config_validation_internal_test.go index 3f4bc3c..1324050 100644 --- a/internal/config/config_validation_internal_test.go +++ b/internal/config/config_validation_internal_test.go @@ -182,6 +182,27 @@ func TestDerivedDBURLOpensStateDirStartingWithTwoSlashes(t *testing.T) { checkDBURLOpensFileInWALMode(t, c.DBURL, filepath.Join(dir, "state.sqlite3")) } +// TestDerivedDBURLForRootStateDir checks the db_url derived from a +// state_dir of /. The path written into the URL is then +// //state.sqlite3, and written right after file: it gives a URL starting +// file://, where SQLite reads state.sqlite3 as a host and refuses to open +// it. The test only checks the URL, since it cannot write to /. +func TestDerivedDBURLForRootStateDir(t *testing.T) { + t.Parallel() + + c, err := configFromYAML(t, signingKeyLine+"state_dir: /\n") + if err != nil { + t.Fatalf("config with state_dir / should be valid, got: %v", err) + } + + t.Logf("state_dir / gives db_url %q", c.DBURL) + + wantDBURL := "file:////state.sqlite3?_pragma=journal_mode(WAL)" + if c.DBURL != wantDBURL { + t.Errorf("DBURL = %q, want %q", c.DBURL, wantDBURL) + } +} + // checkDBURLOpensFileInWALMode opens dbURL with the SQLite driver pixad // uses, and checks that the database is in WAL mode and is the file // dbFile.