dex/functional/repo/testutil.go
Bobby Rullo 84bc8073de functional: Test DBs use migrations
All repo tests build their tables by applying all the migrations. This
way we know our migrations are functional.
2015-08-20 11:44:43 -07:00

27 lines
533 B
Go

package repo
import (
"fmt"
"github.com/coopernurse/gorp"
"github.com/coreos/dex/db"
)
func initDB(dsn string) *gorp.DbMap {
c, err := db.NewConnection(db.Config{DSN: dsn})
if err != nil {
panic(fmt.Sprintf("Unable to connect to database: %v", err))
}
if err = c.DropTablesIfExists(); err != nil {
panic(fmt.Sprintf("Unable to drop database tables: %v", err))
}
if err = db.DropMigrationsTable(c); err != nil {
panic(fmt.Sprintf("Unable to drop migration table: %v", err))
}
db.MigrateToLatest(c)
return c
}