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-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"
|
2019-12-03 17:40:04 +00:00
|
|
|
"storj.io/storj/private/dbutil/pgutil/pgtest"
|
2019-12-05 17:22:27 +00:00
|
|
|
"storj.io/storj/storage/cockroachkv/schema"
|
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()) {
|
2019-12-03 17:40:04 +00:00
|
|
|
if *pgtest.CrdbConnStr == "" {
|
2019-12-05 17:22:27 +00:00
|
|
|
t.Skipf("cockroach flag missing, example:\n-cockroach-test-db=%s", pgtest.DefaultCrdbConnStr)
|
2019-12-03 17:40:04 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 13:57:47 +00:00
|
|
|
tdb, err := cockroachutil.OpenUnique(ctx, *pgtest.CrdbConnStr, "test-schema")
|
2019-12-03 17:40:04 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("init: %+v", err)
|
|
|
|
}
|
|
|
|
|
2020-01-13 13:57:47 +00:00
|
|
|
err = schema.PrepareDB(ctx, tdb.DB)
|
2019-12-05 17:22:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("init: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewWith(tdb.DB), func() {
|
|
|
|
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()
|
|
|
|
|
|
|
|
testsuite.RunTests(t, store)
|
|
|
|
}
|