storj/storagenode/storagenodedb/storagenodedbtest/run.go
Isaac Hess 580e511b4c
storagenode/storagenodedb: Migrate to separate dbs (#3081)
* storagenode/storagenodedb: Migrate to separate dbs

* storagenode/storagenodedb: Add migration to drop versions tables

* Put drop table statements into a transaction.

* Fix CI errors.

* Fix CI errors.

* Changes requested from PR feedback.

* storagenode/storagenodedb: fix tx commit
2019-09-23 12:36:46 -07:00

51 lines
1.1 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package storagenodedbtest
// This package should be referenced only in test files!
import (
"path/filepath"
"testing"
"go.uber.org/zap/zaptest"
"storj.io/storj/internal/testcontext"
"storj.io/storj/storagenode"
"storj.io/storj/storagenode/storagenodedb"
)
// Run method will iterate over all supported databases. Will establish
// connection and will create tables for each DB.
func Run(t *testing.T, test func(t *testing.T, db storagenode.DB)) {
t.Run("Sqlite", func(t *testing.T) {
t.Parallel()
ctx := testcontext.New(t)
defer ctx.Cleanup()
log := zaptest.NewLogger(t)
storageDir := ctx.Dir("storage")
cfg := storagenodedb.Config{
Storage: storageDir,
Info: filepath.Join(storageDir, "piecestore.db"),
Info2: filepath.Join(storageDir, "info.db"),
Pieces: storageDir,
}
db, err := storagenodedb.New(log, cfg)
if err != nil {
t.Fatal(err)
}
defer ctx.Check(db.Close)
err = db.CreateTables(ctx)
if err != nil {
t.Fatal(err)
}
test(t, db)
})
}