Skip to content

Commit

Permalink
db contribs: Can not defer in TestMain due to os.Exit
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgajg1134 committed Dec 5, 2023
1 parent 07bc318 commit 510473a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
6 changes: 4 additions & 2 deletions contrib/database/sql/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ func TestMain(m *testing.M) {
fmt.Println("--- SKIP: to enable integration test, set the INTEGRATION environment variable")
os.Exit(0)
}
defer sqltest.Prepare(tableName)()
os.Exit(m.Run())
cleanup := sqltest.Prepare(tableName)
testResult := m.Run()
cleanup()
os.Exit(testResult)
}

func TestSqlServer(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions contrib/gopkg.in/jinzhu/gorm.v1/gorm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ func TestMain(m *testing.M) {
fmt.Println("--- SKIP: to enable integration test, set the INTEGRATION environment variable")
os.Exit(0)
}
defer sqltest.Prepare(tableName)()
os.Exit(m.Run())
cleanup := sqltest.Prepare(tableName)
testResult := m.Run()
cleanup()
os.Exit(testResult)
}

func TestMySQL(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions contrib/gorm.io/gorm.v1/gorm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ func TestMain(m *testing.M) {
fmt.Println("--- SKIP: to enable integration test, set the INTEGRATION environment variable")
os.Exit(0)
}
defer sqltest.Prepare(tableName)()
os.Exit(m.Run())
cleanup := sqltest.Prepare(tableName)
testResult := m.Run()
cleanup()
os.Exit(testResult)
}

func TestMySQL(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions contrib/jinzhu/gorm/gorm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ func TestMain(m *testing.M) {
fmt.Println("--- SKIP: to enable integration test, set the INTEGRATION environment variable")
os.Exit(0)
}
defer sqltest.Prepare(tableName)()
os.Exit(m.Run())
cleanup := sqltest.Prepare(tableName)
testResult := m.Run()
cleanup()
os.Exit(testResult)
}

func TestSqlServer(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions contrib/jmoiron/sqlx/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ func TestMain(m *testing.M) {
fmt.Println("--- SKIP: to enable integration test, set the INTEGRATION environment variable")
os.Exit(0)
}
defer sqltest.Prepare(tableName)()
os.Exit(m.Run())
cleanup := sqltest.Prepare(tableName)
testResult := m.Run()
cleanup()
os.Exit(testResult)
}

func TestMySQL(t *testing.T) {
Expand Down

0 comments on commit 510473a

Please sign in to comment.