Skip to content

Commit 059a7b2

Browse files
authored
test: update unique constraint error expectations (#5842)
Updates connector-test-kit assertions to match the intentional pg driver-adapter P2002 error target change from field names to database constraint names. ## Changes - **Unique constraint expectations**: Centralizes provider-specific target formatting in the by-OID tests. The pg adapter for PostgreSQL and CockroachDB now asserts model-specific `Parent_pkey` or `Child_pkey` constraints, while Neon and providers that still expose field metadata keep their existing expectations. - **Test support**: Adds `ConnectorVersion::is_pg_driver_adapter()` so tests can distinguish the pg adapter without exposing private connector-version enums. ## Why The pg driver adapter now intentionally preserves the database constraint name for unique violations, while Neon still reports constrained fields. The tests need to distinguish those adapters rather than applying one PostgreSQL-wide expectation. ## Validation - `cargo fmt --all -- --check` - `git diff --check` - Editor diagnostics for the changed test module - Local Cargo checks remain blocked because `openssl-sys` cannot find OpenSSL development headers or `openssl.pc`; CI provides the compile validation. --------- Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent 9999123 commit 059a7b2

2 files changed

Lines changed: 31 additions & 37 deletions

File tree

  • query-engine/connector-test-kit-rs
    • query-engine-tests/tests/writes/ids
    • query-tests-setup/src/connector_tag

query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/ids/byoid.rs

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use query_engine_tests::*;
22

3-
#[test_suite(only(MySql, Postgres, Sqlite, Vitess))]
3+
#[test_suite(only(MySql, Postgres, Sqlite, Vitess, CockroachDb))]
44
// bring_your_own_id
55
mod byoid {
66
use indoc::indoc;
@@ -44,8 +44,22 @@ mod byoid {
4444
schema.to_owned()
4545
}
4646

47+
fn id_unique_constraint_target(runner: &Runner, model: &str) -> String {
48+
match runner.connector_version() {
49+
ConnectorVersion::MySql(_)
50+
| ConnectorVersion::Vitess(Some(query_tests_setup::VitessVersion::PlanetscaleJsWasm)) => {
51+
"constraint: `PRIMARY`".to_owned()
52+
}
53+
connector_version if connector_version.is_pg_driver_adapter() => {
54+
std::format!("constraint: `{model}_pkey`")
55+
}
56+
ConnectorVersion::Vitess(_) => "(not available)".to_owned(),
57+
_ => "fields: (`id`)".to_owned(),
58+
}
59+
}
60+
4761
// "A Create Mutation" should "create and return item with own Id"
48-
#[connector_test(schema(schema_1), only(MySql, Postgres, Sqlite, Vitess))]
62+
#[connector_test(schema(schema_1), only(MySql, Postgres, Sqlite, Vitess, CockroachDb))]
4963
async fn create_and_return_item_woi_1(runner: Runner) -> TestResult<()> {
5064
insta::assert_snapshot!(
5165
run_query!(&runner, r#"mutation {
@@ -54,14 +68,7 @@ mod byoid {
5468
@r###"{"data":{"createOneParent":{"p":"Parent","id":"Own Id"}}}"###
5569
);
5670

57-
let error_target = match runner.connector_version() {
58-
query_engine_tests::ConnectorVersion::MySql(_)
59-
| query_engine_tests::ConnectorVersion::Vitess(Some(query_tests_setup::VitessVersion::PlanetscaleJsWasm)) => {
60-
"constraint: `PRIMARY`"
61-
}
62-
query_engine_tests::ConnectorVersion::Vitess(_) => "(not available)",
63-
_ => "fields: (`id`)",
64-
};
71+
let error_target = id_unique_constraint_target(&runner, "Parent");
6572

6673
assert_error!(
6774
&runner,
@@ -76,7 +83,7 @@ mod byoid {
7683
}
7784

7885
// "A Create Mutation" should "create and return item with own Id"
79-
#[connector_test(schema(schema_2), only(MySql, Postgres, Sqlite, Vitess))]
86+
#[connector_test(schema(schema_2), only(MySql, Postgres, Sqlite, Vitess, CockroachDb))]
8087
async fn create_and_return_item_woi_2(runner: Runner) -> TestResult<()> {
8188
insta::assert_snapshot!(
8289
run_query!(&runner, r#"mutation {
@@ -85,14 +92,7 @@ mod byoid {
8592
@r###"{"data":{"createOneParent":{"p":"Parent","id":"Own Id"}}}"###
8693
);
8794

88-
let error_target = match runner.connector_version() {
89-
query_engine_tests::ConnectorVersion::MySql(_)
90-
| query_engine_tests::ConnectorVersion::Vitess(Some(query_tests_setup::VitessVersion::PlanetscaleJsWasm)) => {
91-
"constraint: `PRIMARY`"
92-
}
93-
ConnectorVersion::Vitess(_) => "(not available)",
94-
_ => "fields: (`id`)",
95-
};
95+
let error_target = id_unique_constraint_target(&runner, "Parent");
9696

9797
assert_error!(
9898
&runner,
@@ -137,7 +137,7 @@ mod byoid {
137137
}
138138

139139
// "A Nested Create Mutation" should "create and return item with own Id"
140-
#[connector_test(schema(schema_1), only(MySql, Postgres, Sqlite, Vitess))]
140+
#[connector_test(schema(schema_1), only(MySql, Postgres, Sqlite, Vitess, CockroachDb))]
141141
async fn nested_create_return_item_woi_1(runner: Runner) -> TestResult<()> {
142142
insta::assert_snapshot!(
143143
run_query!(&runner, r#"mutation {
@@ -146,14 +146,7 @@ mod byoid {
146146
@r###"{"data":{"createOneParent":{"p":"Parent","id":"Own Id","childOpt":{"c":"Child","id":"Own Child Id"}}}}"###
147147
);
148148

149-
let error_target = match runner.connector_version() {
150-
query_engine_tests::ConnectorVersion::MySql(_)
151-
| query_engine_tests::ConnectorVersion::Vitess(Some(query_tests_setup::VitessVersion::PlanetscaleJsWasm)) => {
152-
"constraint: `PRIMARY`"
153-
}
154-
ConnectorVersion::Vitess(_) => "(not available)",
155-
_ => "fields: (`id`)",
156-
};
149+
let error_target = id_unique_constraint_target(&runner, "Child");
157150

158151
assert_error!(
159152
&runner,
@@ -168,7 +161,7 @@ mod byoid {
168161
}
169162

170163
// "A Nested Create Mutation" should "create and return item with own Id"
171-
#[connector_test(schema(schema_2), only(MySql, Postgres, Sqlite, Vitess))]
164+
#[connector_test(schema(schema_2), only(MySql, Postgres, Sqlite, Vitess, CockroachDb))]
172165
async fn nested_create_return_item_woi_2(runner: Runner) -> TestResult<()> {
173166
insta::assert_snapshot!(
174167
run_query!(&runner, r#"mutation {
@@ -177,14 +170,7 @@ mod byoid {
177170
@r###"{"data":{"createOneParent":{"p":"Parent","id":"Own Id","childOpt":{"c":"Child","id":"Own Child Id"}}}}"###
178171
);
179172

180-
let error_target = match runner.connector_version() {
181-
query_engine_tests::ConnectorVersion::MySql(_)
182-
| query_engine_tests::ConnectorVersion::Vitess(Some(query_tests_setup::VitessVersion::PlanetscaleJsWasm)) => {
183-
"constraint: `PRIMARY`"
184-
}
185-
ConnectorVersion::Vitess(_) => "(not available)",
186-
_ => "fields: (`id`)",
187-
};
173+
let error_target = id_unique_constraint_target(&runner, "Child");
188174

189175
assert_error!(
190176
&runner,

query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ impl ConnectorVersion {
271271
}
272272
}
273273

274+
/// Determines if the connector uses the pg driver adapter.
275+
pub fn is_pg_driver_adapter(&self) -> bool {
276+
matches!(
277+
self,
278+
Self::Postgres(Some(PostgresVersion::PgJsWasm)) | Self::CockroachDb(Some(CockroachDbVersion::PgJsWasm))
279+
)
280+
}
281+
274282
/// Determines if the connector uses a driver adapter implemented in Wasm.
275283
/// Do not delete! This is used because the `#[cfg(target_arch = "wasm32")]` conditional compilation
276284
/// directive doesn't work in the test runner.

0 commit comments

Comments
 (0)