Skip to content

Commit

Permalink
Add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman committed May 20, 2023
1 parent 3717a9e commit 951b141
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/e2e/allow_missing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,28 @@ func TestMigrateAllowMissingDown(t *testing.T) {
}
}

func TestUpWithAndWithoutAllowMissing(t *testing.T) {
// Test for https://github.com/pressly/goose/issues/521

// Apply 1,2,4,3 then run up without allow missing. If the next requested migration is
// 4 then it should not raise an error because it has already been applied.
// If goose attempts to apply 4 again then it will raise an error (SQLSTATE 42701) because it
// has already been applied. Specifically it will raise a error.
db := setupTestDB(t, 2)

migrations, err := goose.CollectMigrations(migrationsDir, 0, 4)
check.NoError(t, err)
err = migrations[3].Up(db) // version 4
check.NoError(t, err)
err = migrations[2].Up(db) // version 3
check.NoError(t, err)

err = goose.UpTo(db, migrationsDir, 4)
check.NoError(t, err)
err = goose.UpTo(db, migrationsDir, 4, goose.WithAllowMissing())
check.NoError(t, err)
}

// setupTestDB is helper to setup a DB and apply migrations
// up to the specified version.
func setupTestDB(t *testing.T, version int64) *sql.DB {
Expand Down

0 comments on commit 951b141

Please sign in to comment.