2019-12-03 17:40:04 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
package cockroachkv
|
|
|
|
|
|
|
|
import (
|
2020-01-13 13:57:47 +00:00
|
|
|
"context"
|
2019-12-03 17:40:04 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
_ "github.com/lib/pq"
|
2020-04-24 20:15:27 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-12-03 17:40:04 +00:00
|
|
|
|
2020-01-13 13:57:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
2019-12-05 17:22:27 +00:00
|
|
|
"storj.io/storj/private/dbutil/cockroachutil"
|
2020-04-27 20:34:42 +01:00
|
|
|
"storj.io/storj/private/dbutil/pgtest"
|
2019-12-03 17:40:04 +00:00
|
|
|
"storj.io/storj/storage/testsuite"
|
|
|
|
)
|
|
|
|
|
2020-01-13 13:57:47 +00:00
|
|
|
func newTestCockroachDB(ctx context.Context, t testing.TB) (store *Client, cleanup func()) {
|
2020-04-27 20:34:42 +01:00
|
|
|
connstr := pgtest.PickCockroach(t)
|
2019-12-03 17:40:04 +00:00
|
|
|
|
2020-04-27 20:34:42 +01:00
|
|
|
tdb, err := cockroachutil.OpenUnique(ctx, connstr, "test-schema")
|
2019-12-03 17:40:04 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("init: %+v", err)
|
|
|
|
}
|
|
|
|
|
2020-04-27 20:34:42 +01:00
|
|
|
return NewWith(tdb.DB, connstr), func() {
|
2019-12-05 17:22:27 +00:00
|
|
|
if err := tdb.Close(); err != nil {
|
2019-12-03 17:40:04 +00:00
|
|
|
t.Fatalf("failed to close db: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSuite(t *testing.T) {
|
2020-01-13 13:57:47 +00:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
|
|
|
store, cleanup := newTestCockroachDB(ctx, t)
|
2019-12-03 17:40:04 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
2020-04-24 20:15:27 +01:00
|
|
|
err := store.MigrateToLatest(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-01-22 19:00:46 +00:00
|
|
|
store.SetLookupLimit(500)
|
2019-12-03 17:40:04 +00:00
|
|
|
testsuite.RunTests(t, store)
|
|
|
|
}
|