runTestsParallel runs the tests in parallel with a separate database connection for each test.
(t *testing.T, dsn string, tests ...func(dbt *DBTest, tableName string))
| 204 | |
| 205 | // runTestsParallel runs the tests in parallel with a separate database connection for each test. |
| 206 | func runTestsParallel(t *testing.T, dsn string, tests ...func(dbt *DBTest, tableName string)) { |
| 207 | if !available { |
| 208 | t.Skipf("MySQL server not running on %s", netAddr) |
| 209 | } |
| 210 | |
| 211 | newTableName := func(t *testing.T) string { |
| 212 | t.Helper() |
| 213 | var buf [8]byte |
| 214 | if _, err := rand.Read(buf[:]); err != nil { |
| 215 | t.Fatal(err) |
| 216 | } |
| 217 | return fmt.Sprintf("test_%x", buf[:]) |
| 218 | } |
| 219 | |
| 220 | t.Parallel() |
| 221 | for _, test := range tests { |
| 222 | |
| 223 | t.Run("default", func(t *testing.T) { |
| 224 | t.Parallel() |
| 225 | |
| 226 | tableName := newTableName(t) |
| 227 | db, err := sql.Open("mysql", dsn) |
| 228 | if err != nil { |
| 229 | t.Fatalf("error connecting: %s", err.Error()) |
| 230 | } |
| 231 | t.Cleanup(func() { |
| 232 | db.Exec("DROP TABLE IF EXISTS " + tableName) |
| 233 | db.Close() |
| 234 | }) |
| 235 | |
| 236 | dbt := &DBTest{t, db} |
| 237 | test(dbt, tableName) |
| 238 | }) |
| 239 | |
| 240 | dsn2 := dsn + "&interpolateParams=true" |
| 241 | if _, err := ParseDSN(dsn2); err == errInvalidDSNUnsafeCollation { |
| 242 | t.Run("interpolateParams", func(t *testing.T) { |
| 243 | t.Parallel() |
| 244 | |
| 245 | tableName := newTableName(t) |
| 246 | db, err := sql.Open("mysql", dsn2) |
| 247 | if err != nil { |
| 248 | t.Fatalf("error connecting: %s", err.Error()) |
| 249 | } |
| 250 | t.Cleanup(func() { |
| 251 | db.Exec("DROP TABLE IF EXISTS " + tableName) |
| 252 | db.Close() |
| 253 | }) |
| 254 | |
| 255 | dbt := &DBTest{t, db} |
| 256 | test(dbt, tableName) |
| 257 | }) |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | func (dbt *DBTest) fail(method, query string, err error) { |
| 263 | dbt.Helper() |
no test coverage detected
searching dependent graphs…