MCPcopy
hub / github.com/jackc/pgx / TestConnSendBatchQueryError

Function TestConnSendBatchQueryError

batch_test.go:548–585  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

546}
547
548func TestConnSendBatchQueryError(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 batch := &pgx.Batch{}
556 batch.Queue("select n from generate_series(0,5) n where 100/(5-n) > 0")
557 batch.Queue("select n from generate_series(0,5) n")
558
559 br := conn.SendBatch(ctx, batch)
560
561 rows, err := br.Query()
562 if err != nil {
563 t.Error(err)
564 }
565
566 for i := 0; rows.Next(); i++ {
567 var n int
568 if err := rows.Scan(&n); err != nil {
569 t.Error(err)
570 }
571 if n != i {
572 t.Errorf("n => %v, want %v", n, i)
573 }
574 }
575
576 if pgErr, ok := rows.Err().(*pgconn.PgError); !(ok && pgErr.Code == "22012") {
577 t.Errorf("rows.Err() => %v, want error code %v", rows.Err(), 22012)
578 }
579
580 err = br.Close()
581 if pgErr, ok := err.(*pgconn.PgError); !(ok && pgErr.Code == "22012") {
582 t.Errorf("br.Close() => %v, want error code %v", err, 22012)
583 }
584 })
585}
586
587func TestConnSendBatchQuerySyntaxError(t *testing.T) {
588 t.Parallel()

Callers

nothing calls this directly

Calls 9

QueueMethod · 0.95
RunWithQueryExecModesFunction · 0.92
SendBatchMethod · 0.65
QueryMethod · 0.65
NextMethod · 0.65
ScanMethod · 0.65
ErrMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected