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

Function TestConnExecDeferredError

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

Source from the content-addressed store, hash-verified

1131}
1132
1133func TestConnExecDeferredError(t *testing.T) {
1134 t.Parallel()
1135
1136 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
1137 defer cancel()
1138
1139 pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_DATABASE"))
1140 require.NoError(t, err)
1141 defer closeConn(t, pgConn)
1142
1143 if pgConn.ParameterStatus("crdb_version") != "" {
1144 t.Skip("Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)")
1145 }
1146
1147 setupSQL := `create temporary table t (
1148 id text primary key,
1149 n int not null,
1150 unique (n) deferrable initially deferred
1151 );
1152
1153 insert into t (id, n) values ('a', 1), ('b', 2), ('c', 3);`
1154
1155 _, err = pgConn.Exec(ctx, setupSQL).ReadAll()
1156 assert.NoError(t, err)
1157
1158 _, err = pgConn.Exec(ctx, `update t set n=n+1 where id='b' returning *`).ReadAll()
1159 require.NotNil(t, err)
1160
1161 var pgErr *pgconn.PgError
1162 require.True(t, errors.As(err, &pgErr))
1163 require.Equal(t, "23505", pgErr.Code)
1164
1165 ensureConnValid(t, pgConn)
1166}
1167
1168func TestConnExecContextCanceled(t *testing.T) {
1169 t.Parallel()

Callers

nothing calls this directly

Calls 6

ConnectFunction · 0.92
ParameterStatusMethod · 0.80
ReadAllMethod · 0.80
closeConnFunction · 0.70
ensureConnValidFunction · 0.70
ExecMethod · 0.65

Tested by

no test coverage detected