(t *testing.T)
| 546 | } |
| 547 | |
| 548 | func TestPrepareIdempotency(t *testing.T) { |
| 549 | t.Parallel() |
| 550 | |
| 551 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 552 | defer cancel() |
| 553 | |
| 554 | pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { |
| 555 | for i := range 2 { |
| 556 | _, err := conn.Prepare(context.Background(), "test", "select 42::integer") |
| 557 | if err != nil { |
| 558 | t.Fatalf("%d. Unable to prepare statement: %v", i, err) |
| 559 | } |
| 560 | |
| 561 | var n int32 |
| 562 | err = conn.QueryRow(context.Background(), "test").Scan(&n) |
| 563 | if err != nil { |
| 564 | t.Errorf("%d. Executing prepared statement failed: %v", i, err) |
| 565 | } |
| 566 | |
| 567 | if n != int32(42) { |
| 568 | t.Errorf("%d. Prepared statement did not return expected value: %v", i, n) |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | _, err := conn.Prepare(context.Background(), "test", "select 'fail'::varchar") |
| 573 | if err == nil { |
| 574 | t.Fatalf("Prepare statement with same name but different SQL should have failed but it didn't") |
| 575 | return |
| 576 | } |
| 577 | }) |
| 578 | } |
| 579 | |
| 580 | func TestPrepareStatementCacheModes(t *testing.T) { |
| 581 | t.Parallel() |
nothing calls this directly
no test coverage detected