clean up messy initial comit, remove last traces of working project name, and add resilience to db test.
This commit is contained in:
@@ -13,17 +13,26 @@ var testDB *DB
|
||||
func TestMain(m *testing.M) {
|
||||
testDbConnect := os.Getenv("DB_TEST_CONNECT")
|
||||
if testDbConnect == "" {
|
||||
testDbConnect = "xiaoli_test:test1234@(localhost:3306)/xiaoli_test"
|
||||
testDbConnect = "stufflog_test:test1234@(localhost:3306)/stufflog_test"
|
||||
}
|
||||
|
||||
db, err := Open(testDbConnect)
|
||||
if err != nil {
|
||||
log.Println("DB ERROR", err)
|
||||
for i := 0; i < 10; i++ {
|
||||
db, err := Open(testDbConnect)
|
||||
if err != nil {
|
||||
log.Println("DB ERROR", err)
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
}
|
||||
|
||||
testDB = db
|
||||
}
|
||||
if testDB == nil {
|
||||
log.Println("DB FAILED")
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
|
||||
err = goose.SetDialect("mysql")
|
||||
err := goose.SetDialect("mysql")
|
||||
if err != nil {
|
||||
log.Println("GOOSE ERROR", err)
|
||||
os.Exit(1)
|
||||
@@ -31,20 +40,19 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
for {
|
||||
err = goose.Down(db.db.DB, "../../../migrations/mysql")
|
||||
err = goose.Down(testDB.db.DB, "../../../migrations/mysql")
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = goose.Up(db.db.DB, "../../../migrations/mysql")
|
||||
err = goose.Up(testDB.db.DB, "../../../migrations/mysql")
|
||||
if err != nil && err != goose.ErrNoNextVersion && err != goose.ErrNoCurrentVersion {
|
||||
log.Println("UP ERROR", err)
|
||||
os.Exit(3)
|
||||
return
|
||||
}
|
||||
|
||||
testDB = db
|
||||
code := m.Run()
|
||||
|
||||
os.Exit(code)
|
||||
|
||||
Reference in New Issue
Block a user