Created
April 27, 2020 20:04
-
-
Save tacurran/5d252e8c14a016a01e62277d3b4b438a to your computer and use it in GitHub Desktop.
testgist database migration for @zepatrik
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestMigrations(t *testing.T) { | |
// start a test container and create the database connection | |
connection := dockertest.ConnectToTestPostgreSQLPop(t) | |
// The test migrator searches for testdata SQL files in the ./testdata directory. | |
// After applying each migration it runs its corresponding testdata file. | |
// This test migrator highly depends on the way you apply migrations. | |
testMigrator := NewTestMigrator(t, connection, "../migrations", "./testdata") | |
require.NoError(t, testMigrator.Up()) | |
// there are 10 migrations | |
for i := 0; i < 10; i++ { | |
// get the expected data for the migration | |
expect := expectedData(i) | |
// find the actual data | |
var actual testData | |
connection.Find(&actual, expect.ID) | |
// check if the records are equal | |
assert.Equal(t, expect, actual) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment