(t *testing.T)
| 3455 | } |
| 3456 | |
| 3457 | func TestConnectorTimeoutsWatchCancel(t *testing.T) { |
| 3458 | var ( |
| 3459 | cancel func() // Used to cancel the context just after connecting. |
| 3460 | created *dummyConnection // The created connection. |
| 3461 | ) |
| 3462 | |
| 3463 | RegisterDialContext("TestConnectorTimeoutsWatchCancel", func(ctx context.Context, addr string) (net.Conn, error) { |
| 3464 | // Canceling at this time triggers the watchCancel error branch in Connect(). |
| 3465 | cancel() |
| 3466 | created = &dummyConnection{} |
| 3467 | return created, nil |
| 3468 | }) |
| 3469 | |
| 3470 | mycnf := NewConfig() |
| 3471 | mycnf.User = "root" |
| 3472 | mycnf.Addr = "foo" |
| 3473 | mycnf.Net = "TestConnectorTimeoutsWatchCancel" |
| 3474 | |
| 3475 | conn, err := NewConnector(mycnf) |
| 3476 | if err != nil { |
| 3477 | t.Fatal(err) |
| 3478 | } |
| 3479 | |
| 3480 | db := sql.OpenDB(conn) |
| 3481 | defer db.Close() |
| 3482 | |
| 3483 | var ctx context.Context |
| 3484 | ctx, cancel = context.WithCancel(context.Background()) |
| 3485 | defer cancel() |
| 3486 | |
| 3487 | if _, err := db.Conn(ctx); err != context.Canceled { |
| 3488 | t.Errorf("got %v, want context.Canceled", err) |
| 3489 | } |
| 3490 | |
| 3491 | if created == nil { |
| 3492 | t.Fatal("no connection created") |
| 3493 | } |
| 3494 | if !created.closed { |
| 3495 | t.Errorf("connection not closed") |
| 3496 | } |
| 3497 | } |
| 3498 | |
| 3499 | func TestConnectionAttributes(t *testing.T) { |
| 3500 | if !available { |
nothing calls this directly
no test coverage detected