34 lines
705 B
Go
34 lines
705 B
Go
//go:build integration
|
|
|
|
package dbutil
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/go-sql-driver/mysql"
|
|
)
|
|
|
|
func TestIntegrationOpenMySQLAndCreateDatabaseIfMissing(t *testing.T) {
|
|
dsn := os.Getenv("GITOOCEAN_TEST_MYSQL_DSN")
|
|
if dsn == "" {
|
|
t.Skip("set GITOOCEAN_TEST_MYSQL_DSN to run integration DB tests")
|
|
}
|
|
cfg, err := mysql.ParseDSN(dsn)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.DBName == "" || !strings.Contains(cfg.DBName, "test") {
|
|
t.Fatalf("refusing to run integration test against non-test database %q", cfg.DBName)
|
|
}
|
|
db, err := OpenMySQLAndCreateDatabaseIfMissing(dsn)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer db.Close()
|
|
if err := db.Ping(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|