Skip to content

Commit

Permalink
Make dataDir required on config (#21)
Browse files Browse the repository at this point in the history
This PR removes the WithDataDir() function, which implies that the
datadirectory is optional and enforces it on NewDefaultConfig, since on
its own, the NewDefaultConfig will not spin up a new modusDB instance.
Addressed in

https://linear.app/hypermode/issue/DGR-822/modusdb-newdefaultconfig-fails
  • Loading branch information
jairad26 authored Nov 13, 2024
1 parent ac15c46 commit 0efc77a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
9 changes: 2 additions & 7 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ type Config struct {
limitNormalizeNode int
}

func NewDefaultConfig() Config {
return Config{limitNormalizeNode: 10000}
}

func (cc Config) WithDataDir(dir string) Config {
cc.dataDir = dir
return cc
func NewDefaultConfig(dir string) Config {
return Config{dataDir: dir, limitNormalizeNode: 10000}
}

func (cc Config) WithLimitNormalizeNode(n int) Config {
Expand Down
8 changes: 4 additions & 4 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func TestRestart(t *testing.T) {
dataDir := t.TempDir()

db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(dataDir))
db, err := modusdb.New(modusdb.NewDefaultConfig(dataDir))
require.NoError(t, err)
defer func() { db.Close() }()

Expand Down Expand Up @@ -47,7 +47,7 @@ func TestRestart(t *testing.T) {
require.JSONEq(t, `{"me":[{"name":"A"}]}`, string(qresp.GetJson()))

db.Close()
db, err = modusdb.New(modusdb.NewDefaultConfig().WithDataDir(dataDir))
db, err = modusdb.New(modusdb.NewDefaultConfig(dataDir))
require.NoError(t, err)
qresp, err = db.Query(context.Background(), query)
require.NoError(t, err)
Expand All @@ -57,7 +57,7 @@ func TestRestart(t *testing.T) {
}

func TestSchemaQuery(t *testing.T) {
db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir()))
db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
defer db.Close()

Expand Down Expand Up @@ -86,7 +86,7 @@ func TestBasicVector(t *testing.T) {
}
vectBytes := buf.Bytes()

db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir()))
db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
defer db.Close()

Expand Down
4 changes: 2 additions & 2 deletions live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestLiveLoaderSmall(t *testing.T) {
`
)

db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir()))
db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
defer func() { db.Close() }()

Expand Down Expand Up @@ -83,7 +83,7 @@ func TestLiveLoaderSmall(t *testing.T) {
}

func TestLiveLoader1Million(t *testing.T) {
db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir()))
db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
defer func() { db.Close() }()

Expand Down
2 changes: 1 addition & 1 deletion vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
)

func TestVectorDelete(t *testing.T) {
db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir()))
db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
defer func() { db.Close() }()

Expand Down

0 comments on commit 0efc77a

Please sign in to comment.