From ab29486baebc9a34f4302ac73fe47a66e4cb83f3 Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Thu, 8 Oct 2020 16:15:27 +0100 Subject: [PATCH] test(storage): add test to check for duplicate schema migrations --- storage/migrations/5_scheduler.go | 1 - storage/sql_test.go | 13 +++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/storage/migrations/5_scheduler.go b/storage/migrations/5_scheduler.go index d0da633bd..ad40291c5 100644 --- a/storage/migrations/5_scheduler.go +++ b/storage/migrations/5_scheduler.go @@ -7,7 +7,6 @@ import ( // Schema version 5 is the new scheduler schema func init() { - up := batch(` CREATE TABLE IF NOT EXISTS "visor_processing_statechanges" ( "tip_set" text NOT NULL, diff --git a/storage/sql_test.go b/storage/sql_test.go index ee99b988a..baa44e0b6 100644 --- a/storage/sql_test.go +++ b/storage/sql_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/go-pg/migrations/v8" "github.com/go-pg/pg/v10" "github.com/go-pg/pg/v10/orm" "github.com/stretchr/testify/assert" @@ -14,9 +15,19 @@ import ( "github.com/filecoin-project/sentinel-visor/model/blocks" "github.com/filecoin-project/sentinel-visor/model/messages" "github.com/filecoin-project/sentinel-visor/model/visor" + _ "github.com/filecoin-project/sentinel-visor/storage/migrations" "github.com/filecoin-project/sentinel-visor/testutil" ) +func TestNoDuplicateSchemaMigrations(t *testing.T) { + versions := map[int64]bool{} + ms := migrations.DefaultCollection.Migrations() + for _, m := range ms { + require.False(t, versions[m.Version], "Duplication migration for schema version: %d", m.Version) + versions[m.Version] = true + } +} + func TestSchemaIsCurrent(t *testing.T) { if testing.Short() || !testutil.DatabaseAvailable() { t.Skip("short testing requested or VISOR_TEST_DB not set") @@ -582,7 +593,6 @@ func TestMarkTipSetMessagesComplete(t *testing.T) { require.NoError(t, err) assert.Equal(t, 1, count) }) - } func TestLeaseGasOutputsMessages(t *testing.T) { @@ -852,5 +862,4 @@ func TestMarkGasOutputsMessagesComplete(t *testing.T) { require.NoError(t, err) assert.Equal(t, 1, count) }) - }