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

Function TestConnExecBatchDeferredError

pgconn/pgconn_test.go:1862–1897  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1860}
1861
1862func TestConnExecBatchDeferredError(t *testing.T) {
1863 t.Parallel()
1864
1865 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
1866 defer cancel()
1867
1868 pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_DATABASE"))
1869 require.NoError(t, err)
1870 defer closeConn(t, pgConn)
1871
1872 if pgConn.ParameterStatus("crdb_version") != "" {
1873 t.Skip("Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)")
1874 }
1875
1876 setupSQL := `create temporary table t (
1877 id text primary key,
1878 n int not null,
1879 unique (n) deferrable initially deferred
1880 );
1881
1882 insert into t (id, n) values ('a', 1), ('b', 2), ('c', 3);`
1883
1884 _, err = pgConn.Exec(ctx, setupSQL).ReadAll()
1885 require.NoError(t, err)
1886
1887 batch := &pgconn.Batch{}
1888
1889 batch.ExecParams(`update t set n=n+1 where id='b' returning *`, nil, nil, nil, nil)
1890 _, err = pgConn.ExecBatch(ctx, batch).ReadAll()
1891 require.NotNil(t, err)
1892 var pgErr *pgconn.PgError
1893 require.True(t, errors.As(err, &pgErr))
1894 require.Equal(t, "23505", pgErr.Code)
1895
1896 ensureConnValid(t, pgConn)
1897}
1898
1899func TestConnExecBatchPrecanceled(t *testing.T) {
1900 t.Parallel()

Callers

nothing calls this directly

Calls 8

ExecParamsMethod · 0.95
ConnectFunction · 0.92
ParameterStatusMethod · 0.80
ReadAllMethod · 0.80
ExecBatchMethod · 0.80
closeConnFunction · 0.70
ensureConnValidFunction · 0.70
ExecMethod · 0.65

Tested by

no test coverage detected