mirror of https://github.com/go-gorm/gorm.git
fix: fix the error handle in tests_test
This commit is contained in:
parent
2c3fc2db28
commit
b9667cb747
|
@ -25,12 +25,15 @@ func init() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
} else {
|
} else {
|
||||||
sqlDB, err := DB.DB()
|
sqlDB, err := DB.DB()
|
||||||
if err == nil {
|
|
||||||
err = sqlDB.Ping()
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to connect database, got error %v", err)
|
log.Printf("failed to connect database, got error %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = sqlDB.Ping()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("failed to ping sqlDB, got error %v", err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
RunMigrations()
|
RunMigrations()
|
||||||
|
@ -76,6 +79,10 @@ func OpenTestConnection() (db *gorm.DB, err error) {
|
||||||
db, err = gorm.Open(sqlite.Open(filepath.Join(os.TempDir(), "gorm.db")), &gorm.Config{})
|
db, err = gorm.Open(sqlite.Open(filepath.Join(os.TempDir(), "gorm.db")), &gorm.Config{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if debug := os.Getenv("DEBUG"); debug == "true" {
|
if debug := os.Getenv("DEBUG"); debug == "true" {
|
||||||
db.Logger = db.Logger.LogMode(logger.Info)
|
db.Logger = db.Logger.LogMode(logger.Info)
|
||||||
} else if debug == "false" {
|
} else if debug == "false" {
|
||||||
|
|
Loading…
Reference in New Issue