Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Test against file system #128

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- run:
name: Run tests
command: |
DEFRA_BADGER_MEMORY=true
DEFRA_BADGER_FILE=true
DEFRA_MAP=true
mkdir -p /tmp/test-reports
gotestsum --junitfile /tmp/test-reports/unit-tests.xml
- store_test_results:
Expand Down
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 = false
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