Skip to content

Commit

Permalink
Max integer error messages diverge in driver adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Nov 8, 2023
1 parent f3da57d commit ad0c4c7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ mod max_integer {
schema.to_owned()
}

#[connector_test(schema(overflow_pg), only(Postgres))]
async fn unfitted_int_should_fail_pg(runner: Runner) -> TestResult<()> {
#[connector_test(schema(overflow_pg), only(Postgres), exclude(JS))]
async fn unfitted_int_should_fail_pg_quaint(runner: Runner) -> TestResult<()> {
// int
assert_error!(
runner,
Expand Down Expand Up @@ -234,6 +234,55 @@ mod max_integer {
Ok(())
}

// The driver adapter for neon provides different error messages on overflow
#[connector_test(schema(overflow_pg), only(JS, Postgres))]
async fn unfitted_int_should_fail_pg_js(runner: Runner) -> TestResult<()> {
// int
assert_error!(
runner,
format!("mutation {{ createOneTest(data: {{ int: {I32_OVERFLOW_MAX} }}) {{ id }} }}"),
None,
"value \\\"2147483648\\\" is out of range for type integer"
);
assert_error!(
runner,
format!("mutation {{ createOneTest(data: {{ int: {I32_OVERFLOW_MIN} }}) {{ id }} }}"),
None,
"value \\\"-2147483649\\\" is out of range for type integer"
);

// smallint
assert_error!(
runner,
format!("mutation {{ createOneTest(data: {{ smallint: {I16_OVERFLOW_MAX} }}) {{ id }} }}"),
None,
"value \\\"32768\\\" is out of range for type smallint"
);
assert_error!(
runner,
format!("mutation {{ createOneTest(data: {{ smallint: {I16_OVERFLOW_MIN} }}) {{ id }} }}"),
None,
"value \\\"-32769\\\" is out of range for type smallint"
);

//oid
assert_error!(
runner,
format!("mutation {{ createOneTest(data: {{ oid: {U32_OVERFLOW_MAX} }}) {{ id }} }}"),
None,
"value \\\"4294967296\\\" is out of range for type oid"
);

// The underlying driver swallows a negative id by interpreting it as unsigned.
// {"data":{"createOneTest":{"id":1,"oid":4294967295}}}
run_query!(
runner,
format!("mutation {{ createOneTest(data: {{ oid: {OVERFLOW_MIN} }}) {{ id, oid }} }}")
);

Ok(())
}

#[connector_test(schema(overflow_pg), only(Postgres))]
async fn fitted_int_should_work_pg(runner: Runner) -> TestResult<()> {
// int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,33 @@ pub(crate) fn should_run(
return false;
}

// We skip tests that exclude JS driver adapters when an external test executor is configured.
// A test that you only want to run with rust drivers can be annotated with exclude(JS)
if CONFIG.external_test_executor().is_some() && exclude.iter().any(|excl| excl.0.to_uppercase() == "JS") {
println!("Excluded test execution for JS driver adapters. Skipping test");
return false;
};
// we consume the JS token to prevent it from being used in the following checks
let exclude: Vec<_> = exclude.iter().filter(|excl| excl.0.to_uppercase() != "JS").collect();

// We only run tests that include JS driver adapters when an external test executor is configured.
// A test that you only want to run with js driver adapters can be annotated with only(JS)
if CONFIG.external_test_executor().is_none() && only.iter().any(|incl| incl.0.to_uppercase() == "JS") {
println!("Excluded test execution for rust driver adapters. Skipping test");
return false;
}
// we consume the JS token to prevent it from being used in the following checks
let only: Vec<_> = only.iter().filter(|incl| incl.0.to_uppercase() != "JS").collect();

if !only.is_empty() {
return only
.iter()
.any(|only| ConnectorVersion::try_from(*only).unwrap().matches_pattern(&version));
.any(|incl| ConnectorVersion::try_from(**incl).unwrap().matches_pattern(&version));
}

if exclude.iter().any(|excl| {
ConnectorVersion::try_from(*excl).map_or(false, |connector_version| connector_version.matches_pattern(&version))
ConnectorVersion::try_from(**excl)
.map_or(false, |connector_version| connector_version.matches_pattern(&version))
}) {
println!("Connector excluded. Skipping test.");
return false;
Expand Down

0 comments on commit ad0c4c7

Please sign in to comment.