Ensure migrate tests cleanup after themselves (#1334)
This commit is contained in:
parent
f552e7bc08
commit
c7072620a1
@ -11,7 +11,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"storj.io/storj/internal/dbutil/pgutil"
|
||||
"storj.io/storj/internal/migrate"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
@ -52,12 +54,17 @@ func TestCreate_Postgres(t *testing.T) {
|
||||
t.Skipf("postgres flag missing, example:\n-postgres-test-db=%s", defaultPostgresConn)
|
||||
}
|
||||
|
||||
db, err := sql.Open("postgres", *testPostgres)
|
||||
schema := "create-" + pgutil.RandomString(8)
|
||||
|
||||
db, err := sql.Open("postgres", pgutil.ConnstrWithSchema(*testPostgres, schema))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { assert.NoError(t, db.Close()) }()
|
||||
|
||||
require.NoError(t, pgutil.CreateSchema(db, schema))
|
||||
defer func() { assert.NoError(t, pgutil.DropSchema(db, schema)) }()
|
||||
|
||||
// should create table
|
||||
err = migrate.Create("example", &postgresDB{db, "CREATE TABLE example_table (id text)"})
|
||||
assert.NoError(t, err)
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"github.com/zeebo/errs"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"storj.io/storj/internal/dbutil/pgutil"
|
||||
"storj.io/storj/internal/migrate"
|
||||
"storj.io/storj/internal/testcontext"
|
||||
)
|
||||
@ -33,10 +34,17 @@ func TestBasicMigrationPostgres(t *testing.T) {
|
||||
t.Skipf("postgres flag missing, example:\n-postgres-test-db=%s", defaultPostgresConn)
|
||||
}
|
||||
|
||||
db, err := sql.Open("postgres", *testPostgres)
|
||||
require.NoError(t, err)
|
||||
schema := "create-" + pgutil.RandomString(8)
|
||||
|
||||
db, err := sql.Open("postgres", pgutil.ConnstrWithSchema(*testPostgres, schema))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { assert.NoError(t, db.Close()) }()
|
||||
|
||||
require.NoError(t, pgutil.CreateSchema(db, schema))
|
||||
defer func() { assert.NoError(t, pgutil.DropSchema(db, schema)) }()
|
||||
|
||||
basicMigration(t, db, &postgresDB{DB: db})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user