From 2ff98991a1ed61243f1a39b1ecfe297975c4cf71 Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 11:22:50 +0000 Subject: [PATCH] fix(store): require explicit database path in config Co-Authored-By: Virgil --- store.go | 7 +++++++ store_test.go | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/store.go b/store.go index fba77ce..0ad0496 100644 --- a/store.go +++ b/store.go @@ -45,6 +45,13 @@ type StoreConfig struct { // Usage example: `if err := (store.StoreConfig{DatabasePath: ":memory:", PurgeInterval: 30 * time.Second}).Validate(); err != nil { return }` func (config StoreConfig) Validate() error { + if config.DatabasePath == "" { + return core.E( + "store.StoreConfig.Validate", + "database path is empty", + nil, + ) + } if config.Journal != (JournalConfiguration{}) && !config.Journal.isConfigured() { return core.E( "store.StoreConfig.Validate", diff --git a/store_test.go b/store_test.go index e220a09..e1501c4 100644 --- a/store_test.go +++ b/store_test.go @@ -170,6 +170,12 @@ func TestStore_StoreConfig_Bad_NegativePurgeInterval(t *testing.T) { assert.Contains(t, err.Error(), "purge interval must be zero or positive") } +func TestStore_StoreConfig_Bad_EmptyDatabasePath(t *testing.T) { + err := (StoreConfig{}).Validate() + require.Error(t, err) + assert.Contains(t, err.Error(), "database path is empty") +} + func TestStore_NewConfigured_Bad_NegativePurgeInterval(t *testing.T) { _, err := NewConfigured(StoreConfig{ DatabasePath: ":memory:", @@ -180,6 +186,12 @@ func TestStore_NewConfigured_Bad_NegativePurgeInterval(t *testing.T) { assert.Contains(t, err.Error(), "purge interval must be zero or positive") } +func TestStore_NewConfigured_Bad_EmptyDatabasePath(t *testing.T) { + _, err := NewConfigured(StoreConfig{}) + require.Error(t, err) + assert.Contains(t, err.Error(), "database path is empty") +} + func TestStore_Config_Good(t *testing.T) { storeInstance, err := NewConfigured(StoreConfig{ DatabasePath: ":memory:", -- 2.45.3