From c7072620a1c57d08e270d57bb00e73493323b7c7 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Thu, 21 Feb 2019 11:28:10 +0200 Subject: [PATCH] Ensure migrate tests cleanup after themselves (#1334) --- internal/migrate/create_test.go | 9 ++++++++- internal/migrate/versions_test.go | 12 ++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/internal/migrate/create_test.go b/internal/migrate/create_test.go index acafc6ced..ea8e9a50d 100644 --- a/internal/migrate/create_test.go +++ b/internal/migrate/create_test.go @@ -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) diff --git a/internal/migrate/versions_test.go b/internal/migrate/versions_test.go index dac70b26f..860d1888d 100644 --- a/internal/migrate/versions_test.go +++ b/internal/migrate/versions_test.go @@ -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}) }