Skip to content

Commit

Permalink
dbtest: properly close test connection (#7598)
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed Nov 13, 2023
1 parent b644d79 commit 31a0964
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/dbtest/dbtest.go
Expand Up @@ -55,7 +55,12 @@ func NewDB(t *testing.T, suite string, tables ...any) *gorm.DB {

dbOpts.Name = dbName

cleanup = func(_ *gorm.DB) {
cleanup = func(db *gorm.DB) {
testDB, err := db.DB()
if err == nil {
_ = testDB.Close()
}

_, _ = sqlDB.Exec(fmt.Sprintf("DROP DATABASE `%s`", dbName))
_ = sqlDB.Close()
}
Expand Down Expand Up @@ -86,7 +91,12 @@ func NewDB(t *testing.T, suite string, tables ...any) *gorm.DB {

dbOpts.Name = dbName

cleanup = func(_ *gorm.DB) {
cleanup = func(db *gorm.DB) {
testDB, err := db.DB()
if err == nil {
_ = testDB.Close()
}

_, _ = sqlDB.Exec(fmt.Sprintf(`DROP DATABASE %q`, dbName))
_ = sqlDB.Close()
}
Expand Down

0 comments on commit 31a0964

Please sign in to comment.