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-11-13 16:49:22 +00:00
|
|
|
"database/sql"
|
2019-09-18 17:17:28 +01:00
|
|
|
"path/filepath"
|
2019-03-18 10:55:06 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-11-13 16:49:22 +00:00
|
|
|
"github.com/mattn/go-sqlite3"
|
2019-03-18 10:55:06 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
2021-04-23 10:52:40 +01:00
|
|
|
"storj.io/private/dbutil/utccheck"
|
2019-03-18 10:55:06 +00:00
|
|
|
"storj.io/storj/storagenode"
|
|
|
|
"storj.io/storj/storagenode/storagenodedb"
|
|
|
|
)
|
|
|
|
|
2019-11-13 16:49:22 +00:00
|
|
|
func init() {
|
|
|
|
sql.Register("sqlite3+utccheck", utccheck.WrapDriver(&sqlite3.SQLiteDriver{}))
|
|
|
|
}
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
// Run method will iterate over all supported databases. Will establish
|
|
|
|
// connection and will create tables for each DB.
|
2020-01-20 14:56:12 +00:00
|
|
|
func Run(t *testing.T, test func(ctx *testcontext.Context, t *testing.T, db storagenode.DB)) {
|
2019-03-18 10:55:06 +00:00
|
|
|
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")
|
2022-11-29 20:47:02 +00:00
|
|
|
|
2019-09-18 17:17:28 +01:00
|
|
|
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"),
|
2019-11-13 16:49:22 +00:00
|
|
|
Driver: "sqlite3+utccheck",
|
2019-09-19 20:56:34 +01:00
|
|
|
Pieces: storageDir,
|
2022-11-29 14:12:38 +00:00
|
|
|
|
|
|
|
TestingDisableWAL: true,
|
2019-09-18 17:17:28 +01:00
|
|
|
}
|
|
|
|
|
2022-11-29 20:47:02 +00:00
|
|
|
db, err := OpenNew(ctx, log, cfg)
|
2019-03-18 10:55:06 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer ctx.Check(db.Close)
|
|
|
|
|
2020-04-30 07:36:59 +01:00
|
|
|
err = db.MigrateToLatest(ctx)
|
2019-03-18 10:55:06 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-01-20 14:56:12 +00:00
|
|
|
test(ctx, t, db)
|
2019-03-18 10:55:06 +00:00
|
|
|
})
|
|
|
|
}
|