fix(store): require explicit database path in config

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 11:22:50 +00:00
parent edf9162c21
commit 2ff98991a1
2 changed files with 19 additions and 0 deletions

View file

@ -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",

View file

@ -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:",