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

Function TestBeginReadOnly

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

Source from the content-addressed store, hash-verified

355}
356
357func TestBeginReadOnly(t *testing.T) {
358 t.Parallel()
359 skipCockroachDB(t, "CockroachDB auto commits DDL by default")
360
361 conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
362 defer closeConn(t, conn)
363
364 tx, err := conn.BeginTx(context.Background(), pgx.TxOptions{AccessMode: pgx.ReadOnly})
365 if err != nil {
366 t.Fatalf("conn.Begin failed: %v", err)
367 }
368 defer tx.Rollback(context.Background())
369
370 _, err = conn.Exec(context.Background(), "create table foo(id serial primary key)")
371 if pgErr, ok := err.(*pgconn.PgError); !ok || pgErr.Code != "25006" {
372 t.Errorf("Expected error SQLSTATE 25006, but got %#v", err)
373 }
374}
375
376func TestBeginTxBeginQuery(t *testing.T) {
377 t.Parallel()

Callers

nothing calls this directly

Calls 6

mustConnectStringFunction · 0.85
skipCockroachDBFunction · 0.70
closeConnFunction · 0.70
RollbackMethod · 0.65
ExecMethod · 0.65
BeginTxMethod · 0.45

Tested by

no test coverage detected