(t *testing.T)
| 20 | ) |
| 21 | |
| 22 | func TestConnSendBatch(t *testing.T) { |
| 23 | t.Parallel() |
| 24 | |
| 25 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 26 | defer cancel() |
| 27 | |
| 28 | pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { |
| 29 | pgxtest.SkipCockroachDB(t, conn, "Server serial type is incompatible with test") |
| 30 | |
| 31 | sql := `create temporary table ledger( |
| 32 | id serial primary key, |
| 33 | description varchar not null, |
| 34 | amount int not null |
| 35 | );` |
| 36 | mustExec(t, conn, sql) |
| 37 | |
| 38 | batch := &pgx.Batch{} |
| 39 | batch.Queue("insert into ledger(description, amount) values($1, $2)", "q1", 1) |
| 40 | batch.Queue("insert into ledger(description, amount) values($1, $2)", "q2", 2) |
| 41 | batch.Queue("insert into ledger(description, amount) values($1, $2)", "q3", 3) |
| 42 | batch.Queue("select id, description, amount from ledger order by id") |
| 43 | batch.Queue("select id, description, amount from ledger order by id") |
| 44 | batch.Queue("select * from ledger where false") |
| 45 | batch.Queue("select sum(amount) from ledger") |
| 46 | |
| 47 | br := conn.SendBatch(ctx, batch) |
| 48 | |
| 49 | ct, err := br.Exec() |
| 50 | if err != nil { |
| 51 | t.Error(err) |
| 52 | } |
| 53 | if ct.RowsAffected() != 1 { |
| 54 | t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 1) |
| 55 | } |
| 56 | |
| 57 | ct, err = br.Exec() |
| 58 | if err != nil { |
| 59 | t.Error(err) |
| 60 | } |
| 61 | if ct.RowsAffected() != 1 { |
| 62 | t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 1) |
| 63 | } |
| 64 | |
| 65 | ct, err = br.Exec() |
| 66 | if err != nil { |
| 67 | t.Error(err) |
| 68 | } |
| 69 | if ct.RowsAffected() != 1 { |
| 70 | t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 1) |
| 71 | } |
| 72 | |
| 73 | selectFromLedgerExpectedRows := []struct { |
| 74 | id int32 |
| 75 | description string |
| 76 | amount int32 |
| 77 | }{ |
| 78 | {1, "q1", 1}, |
| 79 | {2, "q2", 2}, |
nothing calls this directly
no test coverage detected