-
Notifications
You must be signed in to change notification settings - Fork 402
/
db.go
48 lines (37 loc) · 1.18 KB
/
db.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
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package testrevocation
import (
"testing"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/testcontext"
"storj.io/storj/pkg/peertls/extensions"
"storj.io/storj/pkg/revocation"
"storj.io/storj/storage"
"storj.io/storj/storage/redis/redisserver"
)
// RunDBs runs the passed test function with each type of revocation database.
func RunDBs(t *testing.T, test func(*testing.T, extensions.RevocationDB, storage.KeyValueStore)) {
t.Run("Redis", func(t *testing.T) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
addr, cleanup, err := redisserver.Start()
require.NoError(t, err)
defer cleanup()
// Test using redis-backed revocation DB
dbURL := "redis://" + addr + "?db=0"
db, err := revocation.NewDB(dbURL)
require.NoError(t, err)
defer ctx.Check(db.Close)
test(t, db, db.TestGetStore())
})
t.Run("Bolt", func(t *testing.T) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
// Test using bolt-backed revocation DB
db, err := revocation.NewDB("bolt://" + ctx.File("revocations.db"))
require.NoError(t, err)
defer ctx.Check(db.Close)
test(t, db, db.TestGetStore())
})
}