From b9667cb747341fbab197f9ccde1ddea864099171 Mon Sep 17 00:00:00 2001 From: "liweiting.wt" Date: Tue, 28 Dec 2021 18:22:17 +0800 Subject: [PATCH] fix: fix the error handle in tests_test --- tests/tests_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/tests_test.go b/tests/tests_test.go index d1f19df3..e26f358d 100644 --- a/tests/tests_test.go +++ b/tests/tests_test.go @@ -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" {