2019-03-18 10:55:06 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package storagenodedbtest
|
|
|
|
|
|
|
|
// This package should be referenced only in test files!
|
|
|
|
|
|
|
|
import (
|
2019-09-18 17:17:28 +01:00
|
|
|
"path/filepath"
|
2019-03-18 10:55:06 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"go.uber.org/zap/zaptest"
|
|
|
|
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testcontext"
|
2019-03-18 10:55:06 +00:00
|
|
|
"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)
|
|
|
|
|
2019-09-18 17:17:28 +01:00
|
|
|
storageDir := ctx.Dir("storage")
|
|
|
|
cfg := storagenodedb.Config{
|
2019-09-19 20:56:34 +01:00
|
|
|
Storage: storageDir,
|
|
|
|
Info: filepath.Join(storageDir, "piecestore.db"),
|
|
|
|
Info2: filepath.Join(storageDir, "info.db"),
|
|
|
|
Pieces: storageDir,
|
2019-09-18 17:17:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
db, err := storagenodedb.New(log, cfg)
|
2019-03-18 10:55:06 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer ctx.Check(db.Close)
|
|
|
|
|
2019-09-23 20:36:46 +01:00
|
|
|
err = db.CreateTables(ctx)
|
2019-03-18 10:55:06 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
test(t, db)
|
|
|
|
})
|
|
|
|
}
|