diff --git a/tests/migration_dependency_test.go b/tests/migration_dependency_test.go index a73136b3..ec828743 100644 --- a/tests/migration_dependency_test.go +++ b/tests/migration_dependency_test.go @@ -1,9 +1,12 @@ package tests import ( - "github.com/flanksource/duty/migrate" + "github.com/flanksource/commons/collections" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + + "github.com/flanksource/duty/api" + "github.com/flanksource/duty/migrate" ) var _ = Describe("migration dependency", Ordered, func() { @@ -18,34 +21,34 @@ var _ = Describe("migration dependency", Ordered, func() { }) // FIXME: sql driver issue on CI - // It("should get correct executable scripts", func() { - // err := DefaultContext.DB().Exec(`UPDATE migration_logs SET hash = 'dummy' WHERE path = 'drop.sql'`).Error - // Expect(err).To(BeNil()) - // - // db, err := DefaultContext.DB().DB() - // Expect(err).To(BeNil()) - // - // funcs, views, err := migrate.GetExecutableScripts(db) - // Expect(err).To(BeNil()) - // Expect(len(funcs)).To(Equal(1)) - // Expect(len(views)).To(Equal(2)) - // - // Expect(collections.MapKeys(funcs)).To(Equal([]string{"drop.sql"})) - // Expect(collections.MapKeys(views)).To(ConsistOf([]string{"006_config_views.sql", "021_notification.sql"})) - // - // { - // // run the migrations again to ensure that the hashes are repopulated - // err := migrate.RunMigrations(db, api.DefaultConfig) - // Expect(err).To(BeNil()) - // - // // at the end, there should be no scrips to apply - // db, err := DefaultContext.DB().DB() - // Expect(err).To(BeNil()) - // - // funcs, views, err := migrate.GetExecutableScripts(db) - // Expect(err).To(BeNil()) - // Expect(len(funcs)).To(BeZero()) - // Expect(len(views)).To(BeZero()) - // } - // }) + It("should get correct executable scripts", func() { + err := DefaultContext.DB().Exec(`UPDATE migration_logs SET hash = 'dummy' WHERE path = 'drop.sql'`).Error + Expect(err).To(BeNil()) + + db, err := DefaultContext.DB().DB() + Expect(err).To(BeNil()) + + funcs, views, err := migrate.GetExecutableScripts(db) + Expect(err).To(BeNil()) + Expect(len(funcs)).To(Equal(1)) + Expect(len(views)).To(Equal(2)) + + Expect(collections.MapKeys(funcs)).To(Equal([]string{"drop.sql"})) + Expect(collections.MapKeys(views)).To(ConsistOf([]string{"006_config_views.sql", "021_notification.sql"})) + + { + // run the migrations again to ensure that the hashes are repopulated + err := migrate.RunMigrations(db, api.DefaultConfig) + Expect(err).To(BeNil()) + + // at the end, there should be no scrips to apply + db, err := DefaultContext.DB().DB() + Expect(err).To(BeNil()) + + funcs, views, err := migrate.GetExecutableScripts(db) + Expect(err).To(BeNil()) + Expect(len(funcs)).To(BeZero()) + Expect(len(views)).To(BeZero()) + } + }) })