| 2320 | } |
| 2321 | |
| 2322 | func TestPing(t *testing.T) { |
| 2323 | ctx := context.Background() |
| 2324 | runTests(t, dsn, func(dbt *DBTest) { |
| 2325 | if err := dbt.db.Ping(); err != nil { |
| 2326 | dbt.fail("Ping", "Ping", err) |
| 2327 | } |
| 2328 | }) |
| 2329 | |
| 2330 | runTests(t, dsn, func(dbt *DBTest) { |
| 2331 | conn, err := dbt.db.Conn(ctx) |
| 2332 | if err != nil { |
| 2333 | dbt.fail("db", "Conn", err) |
| 2334 | } |
| 2335 | |
| 2336 | // Check that affectedRows and insertIds are cleared after each call. |
| 2337 | conn.Raw(func(conn any) error { |
| 2338 | c := conn.(*mysqlConn) |
| 2339 | |
| 2340 | // Issue a query that sets affectedRows and insertIds. |
| 2341 | q, err := c.Query(`SELECT 1`, nil) |
| 2342 | if err != nil { |
| 2343 | dbt.fail("Conn", "Query", err) |
| 2344 | } |
| 2345 | if got, want := c.result.affectedRows, []int64{0}; !reflect.DeepEqual(got, want) { |
| 2346 | dbt.Fatalf("bad affectedRows: got %v, want=%v", got, want) |
| 2347 | } |
| 2348 | if got, want := c.result.insertIds, []int64{0}; !reflect.DeepEqual(got, want) { |
| 2349 | dbt.Fatalf("bad insertIds: got %v, want=%v", got, want) |
| 2350 | } |
| 2351 | q.Close() |
| 2352 | |
| 2353 | // Verify that Ping() clears both fields. |
| 2354 | for range 2 { |
| 2355 | if err := c.Ping(ctx); err != nil { |
| 2356 | dbt.fail("Pinger", "Ping", err) |
| 2357 | } |
| 2358 | if got, want := c.result.affectedRows, []int64(nil); !reflect.DeepEqual(got, want) { |
| 2359 | t.Errorf("bad affectedRows: got %v, want=%v", got, want) |
| 2360 | } |
| 2361 | if got, want := c.result.insertIds, []int64(nil); !reflect.DeepEqual(got, want) { |
| 2362 | t.Errorf("bad affectedRows: got %v, want=%v", got, want) |
| 2363 | } |
| 2364 | } |
| 2365 | return nil |
| 2366 | }) |
| 2367 | }) |
| 2368 | } |
| 2369 | |
| 2370 | // See Issue #799 |
| 2371 | func TestEmptyPassword(t *testing.T) { |