Merge pull request #4964 from liweitingwt/f_test_error

improve the error handle in tests_test
This commit is contained in:
kinggo 2021-12-31 14:25:04 +08:00 committed by GitHub
commit 4dd2647967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 4 deletions

View File

@ -25,12 +25,15 @@ func init() {
os.Exit(1)
} else {
sqlDB, err := DB.DB()
if err == nil {
err = sqlDB.Ping()
}
if err != nil {
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()
@ -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{})
}
if err != nil {
return
}
if debug := os.Getenv("DEBUG"); debug == "true" {
db.Logger = db.Logger.LogMode(logger.Info)
} else if debug == "false" {