storj/storage/cockroachkv/client_test.go
paul cannon bbdb351e5e all: use jackc/pgx in place of lib/pq
What:

Use the github.com/jackc/pgx postgresql driver in place of
github.com/lib/pq.

Why:

github.com/lib/pq has some problems with error handling and context
cancellations (i.e. it might even issue queries or DML statements more
than once! see https://github.com/lib/pq/issues/939). The
github.com/jackx/pgx library appears not to have these problems, and
also appears to be better engineered and implemented (in particular, it
doesn't use "exceptions by panic"). It should also give us some
performance improvements in some cases, and even more so if we can use
it directly instead of going through the database/sql layer.

Change-Id: Ia696d220f340a097dee9550a312d37de14ed2044
2020-07-13 15:54:41 +00:00

45 lines
974 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package cockroachkv
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/testcontext"
"storj.io/storj/private/dbutil/cockroachutil"
"storj.io/storj/private/dbutil/pgtest"
"storj.io/storj/storage/testsuite"
)
func newTestCockroachDB(ctx context.Context, t testing.TB) (store *Client, cleanup func()) {
connstr := pgtest.PickCockroach(t)
tdb, err := cockroachutil.OpenUnique(ctx, connstr, "test-schema")
if err != nil {
t.Fatalf("init: %+v", err)
}
return NewWith(tdb.DB, connstr), func() {
if err := tdb.Close(); err != nil {
t.Fatalf("failed to close db: %v", err)
}
}
}
func TestSuite(t *testing.T) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
store, cleanup := newTestCockroachDB(ctx, t)
defer cleanup()
err := store.MigrateToLatest(ctx)
require.NoError(t, err)
store.SetLookupLimit(500)
testsuite.RunTests(t, store)
}