mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-20 16:45:56 +08:00
37 lines
528 B
Go
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{}) {}
|