mirror of https://github.com/dexidp/dex.git
9 changed files with 118 additions and 176 deletions
@ -1,28 +1,38 @@
|
||||
package repo |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
"testing" |
||||
|
||||
"github.com/coreos/dex/db" |
||||
"github.com/go-gorp/gorp" |
||||
|
||||
"github.com/coreos/dex/db" |
||||
) |
||||
|
||||
func initDB(dsn string) *gorp.DbMap { |
||||
func connect(t *testing.T) *gorp.DbMap { |
||||
dsn := os.Getenv("DEX_TEST_DSN") |
||||
if dsn == "" { |
||||
t.Fatal("DEX_TEST_DSN environment variable not set") |
||||
} |
||||
c, err := db.NewConnection(db.Config{DSN: dsn}) |
||||
if err != nil { |
||||
panic(fmt.Sprintf("Unable to connect to database: %v", err)) |
||||
t.Fatalf("Unable to connect to database: %v", err) |
||||
} |
||||
|
||||
if err = c.DropTablesIfExists(); err != nil { |
||||
panic(fmt.Sprintf("Unable to drop database tables: %v", err)) |
||||
t.Fatalf("Unable to drop database tables: %v", err) |
||||
} |
||||
|
||||
if err = db.DropMigrationsTable(c); err != nil { |
||||
panic(fmt.Sprintf("Unable to drop migration table: %v", err)) |
||||
t.Fatalf("Unable to drop migration table: %v", err) |
||||
} |
||||
|
||||
if _, err = db.MigrateToLatest(c); err != nil { |
||||
panic(fmt.Sprintf("Unable to migrate: %v", err)) |
||||
n, err := db.MigrateToLatest(c) |
||||
if err != nil { |
||||
t.Fatalf("Unable to migrate: %v", err) |
||||
} |
||||
if n == 0 { |
||||
t.Fatalf("No migrations performed") |
||||
} |
||||
|
||||
return c |
||||
} |
||||
|
||||
Loading…
Reference in new issue