2019-08-20 16:04:17 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package testrevocation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/peertls/extensions"
|
|
|
|
"storj.io/common/testcontext"
|
2019-08-20 16:04:17 +01:00
|
|
|
"storj.io/storj/pkg/revocation"
|
2021-03-09 17:42:10 +00:00
|
|
|
"storj.io/storj/private/testredis"
|
2019-08-20 16:04:17 +01:00
|
|
|
"storj.io/storj/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
|
2021-03-09 17:42:10 +00:00
|
|
|
redis, err := testredis.Mini(ctx)
|
2019-08-20 16:04:17 +01:00
|
|
|
require.NoError(t, err)
|
2020-01-31 18:28:42 +00:00
|
|
|
defer ctx.Check(redis.Close)
|
2019-08-20 16:04:17 +01:00
|
|
|
|
|
|
|
// Test using redis-backed revocation DB
|
2020-01-31 18:28:42 +00:00
|
|
|
dbURL := "redis://" + redis.Addr() + "?db=0"
|
2020-10-28 14:01:41 +00:00
|
|
|
db, err := revocation.OpenDB(ctx, dbURL)
|
2019-08-20 16:04:17 +01:00
|
|
|
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
|
2020-10-28 14:01:41 +00:00
|
|
|
db, err := revocation.OpenDB(ctx, "bolt://"+ctx.File("revocations.db"))
|
2019-08-20 16:04:17 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer ctx.Check(db.Close)
|
|
|
|
|
|
|
|
test(t, db, db.TestGetStore())
|
|
|
|
})
|
|
|
|
}
|