100-go-mistakes/11-testing/90-testing-features/setup-teardown/main_test.go
2022-02-07 09:51:28 +01:00

37 lines
479 B
Go

package main
import (
"database/sql"
"os"
"testing"
)
func TestMySQLIntegration(t *testing.T) {
setupMySQL()
defer teardownMySQL()
// ...
}
func createConnection(t *testing.T, dsn string) *sql.DB {
db, err := sql.Open("mysql", dsn)
if err != nil {
t.FailNow()
}
t.Cleanup(
func() {
_ = db.Close()
})
return db
}
func TestMain(m *testing.M) {
setupMySQL()
code := m.Run()
teardownMySQL()
os.Exit(code)
}
func setupMySQL() {}
func teardownMySQL() {}