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

Function TestTransactionSuccessfulCommit

tx_test.go:16–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestTransactionSuccessfulCommit(t *testing.T) {
17 t.Parallel()
18
19 conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
20 defer closeConn(t, conn)
21
22 createSql := `
23 create temporary table foo(
24 id integer,
25 unique (id)
26 );
27 `
28
29 if _, err := conn.Exec(context.Background(), createSql); err != nil {
30 t.Fatalf("Failed to create table: %v", err)
31 }
32
33 tx, err := conn.Begin(context.Background())
34 if err != nil {
35 t.Fatalf("conn.Begin failed: %v", err)
36 }
37
38 _, err = tx.Exec(context.Background(), "insert into foo(id) values (1)")
39 if err != nil {
40 t.Fatalf("tx.Exec failed: %v", err)
41 }
42
43 err = tx.Commit(context.Background())
44 if err != nil {
45 t.Fatalf("tx.Commit failed: %v", err)
46 }
47
48 var n int64
49 err = conn.QueryRow(context.Background(), "select count(*) from foo").Scan(&n)
50 if err != nil {
51 t.Fatalf("QueryRow Scan failed: %v", err)
52 }
53 if n != 1 {
54 t.Fatalf("Did not receive correct number of rows: %v", n)
55 }
56}
57
58func TestTxCommitWhenTxBroken(t *testing.T) {
59 t.Parallel()

Callers

nothing calls this directly

Calls 7

mustConnectStringFunction · 0.85
closeConnFunction · 0.70
ExecMethod · 0.65
BeginMethod · 0.65
CommitMethod · 0.65
ScanMethod · 0.65
QueryRowMethod · 0.65

Tested by

no test coverage detected