MCPcopy Index your code
hub / github.com/helm/helm / TestSqlCheckAppliedMigrations

Function TestSqlCheckAppliedMigrations

pkg/storage/driver/sql_test.go:580–626  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

578}
579
580func 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}

Callers

nothing calls this directly

Calls 2

newTestFixtureSQLFunction · 0.85
checkAlreadyAppliedMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…