Example #1
0
func expectedMigrationActiveQuery(id string, active bool) {
	expectedSQL := fmt.Sprintf(
		"SELECT id FROM %s WHERE migration_id=?",
		config.MigrationsTableName,
	)
	query := sqlmock.ExpectQuery(regexp.QuoteMeta(expectedSQL)).
		WithArgs(id)

	if active {
		query.WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1))
	} else {
		query.WillReturnError(sql.ErrNoRows)
	}
}
Example #2
0
					err := DeleteMigration(ID)
					Expect(err).NotTo(HaveOccurred())
				})
			})

			Describe(".MigrationActive", func() {
				Context("when the migration is active", func() {
					It("returns true", func() {
						ID := "123"
						expectedSQL := fmt.Sprintf(
							"SELECT id FROM %s WHERE migration_id=?",
							config.MigrationsTableName,
						)
						sqlmock.ExpectQuery(regexp.QuoteMeta(expectedSQL)).
							WithArgs(ID).
							WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1))

						active, err := MigrationActive(ID)

						Expect(active).To(BeTrue())
						Expect(err).NotTo(HaveOccurred())
					})
				})

				Context("when the migration is inactive", func() {
					It("returns false", func() {
						ID := "123"
						expectedSQL := fmt.Sprintf(
							"SELECT id FROM %s WHERE migration_id=?",
							config.MigrationsTableName,
						)