100-go-mistakes/11-testing/90-testing-features/setup-teardown/main_test.go
2021-12-27 15:56:17 +01:00

37 lines
528 B
Go

package main
import (
"database/sql"
"os"
"testing"
)
func TestMySQLIntegration(t *testing.T) {
s := setupMySQL()
defer teardownMySQL(s)
// ...
}
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) {
s := setupMySQL()
code := m.Run()
teardownMySQL(s)
os.Exit(code)
}
func setupMySQL() interface{} { return nil }
func teardownMySQL(m interface{}) {}