Skip to content

Commit

Permalink
WIP - Run tests using badger-file as well as IM options
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Jan 20, 2022
1 parent 746aec2 commit 411f55b
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions db/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ type databaseInfo struct {
}

var badgerInMemory bool
var badgerFile bool
var mapStore bool

func init() {
// We use environment variables instead of flags `go test ./...` throws for all packages that don't have the flag defined
_, badgerInMemory = os.LookupEnv("DEFRA_BADGER_MEMORY")
_, badgerFile = os.LookupEnv("DEFRA_BADGER_FILE")
_, mapStore = os.LookupEnv("DEFRA_MAP")

// default is to run against all
if !badgerInMemory && !mapStore {
if !badgerInMemory && !badgerFile && !mapStore {
badgerInMemory = true
// Testing against the file system is off by default
badgerFile = true
mapStore = true
}
}
Expand Down Expand Up @@ -87,7 +91,27 @@ func newMapDB() (databaseInfo, error) {
}, nil
}

func getDatabases() ([]databaseInfo, error) {
func newBadgerFileDB(t *testing.T) (databaseInfo, error) {
path := t.TempDir()

opts := badgerds.Options{Options: badger.DefaultOptions(path)}
rootstore, err := badgerds.NewDatastore(path, &opts)
if err != nil {
return databaseInfo{}, err
}

db, err := db.NewDB(rootstore, struct{}{})
if err != nil {
return databaseInfo{}, err
}

return databaseInfo{
name: "badger-file-system",
db: db,
}, nil
}

func getDatabases(t *testing.T) ([]databaseInfo, error) {
databases := []databaseInfo{}

if badgerInMemory {
Expand All @@ -98,6 +122,14 @@ func getDatabases() ([]databaseInfo, error) {
databases = append(databases, badgerIMDatabase)
}

if badgerFile {
badgerIMDatabase, err := newBadgerFileDB(t)
if err != nil {
return nil, err
}
databases = append(databases, badgerIMDatabase)
}

if mapStore {
mapDatabase, err := newMapDB()
if err != nil {
Expand All @@ -111,7 +143,7 @@ func getDatabases() ([]databaseInfo, error) {

func ExecuteQueryTestCase(t *testing.T, schema string, collectionNames []string, test QueryTestCase) {
ctx := context.Background()
dbs, err := getDatabases()
dbs, err := getDatabases(t)
assert.NoError(t, err)
assert.NotEmpty(t, dbs)

Expand Down

0 comments on commit 411f55b

Please sign in to comment.