Exemplo n.º 1
0
func TruncateTables(database *db.DB) {
	env := application.NewEnvironment()
	dbMigrator := v1models.DatabaseMigrator{}
	dbMigrator.Migrate(database.RawConnection(), env.ModelMigrationsPath)
	v1models.Setup(database)
	v2models.Setup(database)

	connection := database.Connection().(*db.Connection)
	err := connection.TruncateTables()
	if err != nil {
		panic(err)
	}
}
var _ = Describe("DatabaseMigrator", func() {
	var (
		database            *db.DB
		connection          *db.Connection
		dbMigrator          models.DatabaseMigrator
		defaultTemplatePath string
	)

	BeforeEach(func() {
		env := application.NewEnvironment()
		defaultTemplatePath = env.RootPath + "/templates/default.json"
		database = db.NewDatabase(sqlDB, db.Config{
			DefaultTemplatePath: defaultTemplatePath,
		})
		helpers.TruncateTables(database)
		connection = database.Connection().(*db.Connection)
		dbMigrator = models.DatabaseMigrator{}
	})

	Describe("migrating the database", func() {
		It("has the correct tables", func() {
			err := connection.Db.Ping()
			Expect(err).To(BeNil())

			rows, err := connection.Db.Query("SHOW TABLES")
			Expect(err).To(BeNil())

			tables := []string{}
			for rows.Next() {
				var table string
				err = rows.Scan(&table)
Exemplo n.º 3
0
package db_test

import (
	"github.com/cloudfoundry-incubator/notifications/db"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Database", func() {
	var database *db.DB

	BeforeEach(func() {
		database = db.NewDatabase(sqlDB, db.Config{})
	})

	Describe("Connection", func() {
		It("returns a Connection", func() {
			connection := database.Connection()
			Expect(connection).To(BeAssignableToTypeOf(&db.Connection{}))
		})
	})
})