-
Notifications
You must be signed in to change notification settings - Fork 402
/
run.go
58 lines (46 loc) · 1.31 KB
/
run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package storagenodedbtest
// This package should be referenced only in test files!
import (
"database/sql"
"path/filepath"
"testing"
"github.com/mattn/go-sqlite3"
"go.uber.org/zap/zaptest"
"storj.io/common/testcontext"
"storj.io/private/dbutil/utccheck"
"storj.io/storj/storagenode"
"storj.io/storj/storagenode/storagenodedb"
)
func init() {
sql.Register("sqlite3+utccheck", utccheck.WrapDriver(&sqlite3.SQLiteDriver{}))
}
// 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(ctx *testcontext.Context, 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"),
Driver: "sqlite3+utccheck",
Pieces: storageDir,
}
db, err := storagenodedb.OpenNew(ctx, log, cfg)
if err != nil {
t.Fatal(err)
}
defer ctx.Check(db.Close)
err = db.MigrateToLatest(ctx)
if err != nil {
t.Fatal(err)
}
test(ctx, t, db)
})
}