(t *testing.T)
| 578 | } |
| 579 | |
| 580 | func TestSqlCheckAppliedMigrations(t *testing.T) { |
| 581 | cases := []struct { |
| 582 | migrationsToApply []*migrate.Migration |
| 583 | appliedMigrationsIDs []string |
| 584 | expectedResult bool |
| 585 | errorExplanation string |
| 586 | }{ |
| 587 | { |
| 588 | migrationsToApply: []*migrate.Migration{{Id: "init1"}, {Id: "init2"}, {Id: "init3"}}, |
| 589 | appliedMigrationsIDs: []string{"1", "2", "init1", "3", "init2", "4", "5"}, |
| 590 | expectedResult: false, |
| 591 | errorExplanation: "Has found one migration id \"init3\" as applied, that was not applied", |
| 592 | }, |
| 593 | { |
| 594 | migrationsToApply: []*migrate.Migration{{Id: "init1"}, {Id: "init2"}, {Id: "init3"}}, |
| 595 | appliedMigrationsIDs: []string{"1", "2", "init1", "3", "init2", "4", "init3", "5"}, |
| 596 | expectedResult: true, |
| 597 | errorExplanation: "Has not found one or more migration ids, that was applied", |
| 598 | }, |
| 599 | { |
| 600 | migrationsToApply: []*migrate.Migration{{Id: "init"}}, |
| 601 | appliedMigrationsIDs: []string{"1", "2", "3", "inits", "4", "tinit", "5"}, |
| 602 | expectedResult: false, |
| 603 | errorExplanation: "Has found single \"init\", that was not applied", |
| 604 | }, |
| 605 | { |
| 606 | migrationsToApply: []*migrate.Migration{{Id: "init"}}, |
| 607 | appliedMigrationsIDs: []string{"1", "2", "init", "3", "init2", "4", "init3", "5"}, |
| 608 | expectedResult: true, |
| 609 | errorExplanation: "Has not found single migration id \"init\", that was applied", |
| 610 | }, |
| 611 | } |
| 612 | for i, c := range cases { |
| 613 | sqlDriver, mock := newTestFixtureSQL(t) |
| 614 | rows := sqlmock.NewRows([]string{"id", "applied_at"}) |
| 615 | for _, id := range c.appliedMigrationsIDs { |
| 616 | rows.AddRow(id, time.Time{}) |
| 617 | } |
| 618 | mock. |
| 619 | ExpectQuery(""). |
| 620 | WillReturnRows(rows) |
| 621 | mock.ExpectCommit() |
| 622 | if sqlDriver.checkAlreadyApplied(c.migrationsToApply) != c.expectedResult { |
| 623 | t.Errorf("Test case: %v, Expected: %v, Have: %v, Explanation: %v", i, c.expectedResult, !c.expectedResult, c.errorExplanation) |
| 624 | } |
| 625 | } |
| 626 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…