From b5bf74904872aac6a98883db153c14d767a3ba67 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Mon, 28 Jul 2025 09:57:02 -0500 Subject: [PATCH 1/3] Update Invalid URI test for CDRIVER-5983 --- src/mongocxx/test/v_noabi/uri.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mongocxx/test/v_noabi/uri.cpp b/src/mongocxx/test/v_noabi/uri.cpp index 45dc56dc86..3ae56ba49e 100644 --- a/src/mongocxx/test/v_noabi/uri.cpp +++ b/src/mongocxx/test/v_noabi/uri.cpp @@ -72,7 +72,8 @@ TEST_CASE("URI", "[uri]") { } catch (mongocxx::logic_error const& e) { REQUIRE(e.code() == mongocxx::error_code::k_invalid_uri); - std::string invalid_schema = "Invalid URI Schema, expecting 'mongodb://' or 'mongodb+srv://': "; + std::string invalid_schema = + "Invalid URI scheme \"mongo://\". Expected one of \"mongodb://\" or \"mongodb+srv://\": "; REQUIRE(e.what() == invalid_schema + e.code().message()); } From 0b0e8011ad423000c15c237360fbfcacb6ecd1ed Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Mon, 28 Jul 2025 10:03:32 -0500 Subject: [PATCH 2/3] Revert "Update Invalid URI test for CDRIVER-5983" This reverts commit b5bf74904872aac6a98883db153c14d767a3ba67. --- src/mongocxx/test/v_noabi/uri.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mongocxx/test/v_noabi/uri.cpp b/src/mongocxx/test/v_noabi/uri.cpp index 3ae56ba49e..45dc56dc86 100644 --- a/src/mongocxx/test/v_noabi/uri.cpp +++ b/src/mongocxx/test/v_noabi/uri.cpp @@ -72,8 +72,7 @@ TEST_CASE("URI", "[uri]") { } catch (mongocxx::logic_error const& e) { REQUIRE(e.code() == mongocxx::error_code::k_invalid_uri); - std::string invalid_schema = - "Invalid URI scheme \"mongo://\". Expected one of \"mongodb://\" or \"mongodb+srv://\": "; + std::string invalid_schema = "Invalid URI Schema, expecting 'mongodb://' or 'mongodb+srv://': "; REQUIRE(e.what() == invalid_schema + e.code().message()); } From da8b223ef74a325d0dcf1c844aebb566fbdaf064 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Mon, 28 Jul 2025 10:11:15 -0500 Subject: [PATCH 3/3] Use ContainsSubstring to match both 2.0.0 and 2.1.0 mongoc error messages --- src/mongocxx/test/v_noabi/uri.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/mongocxx/test/v_noabi/uri.cpp b/src/mongocxx/test/v_noabi/uri.cpp index 45dc56dc86..20edf03625 100644 --- a/src/mongocxx/test/v_noabi/uri.cpp +++ b/src/mongocxx/test/v_noabi/uri.cpp @@ -25,6 +25,8 @@ #include +#include + namespace { TEST_CASE("URI", "[uri]") { SECTION("Default URI") { @@ -72,9 +74,16 @@ TEST_CASE("URI", "[uri]") { } catch (mongocxx::logic_error const& e) { REQUIRE(e.code() == mongocxx::error_code::k_invalid_uri); - std::string invalid_schema = "Invalid URI Schema, expecting 'mongodb://' or 'mongodb+srv://': "; - - REQUIRE(e.what() == invalid_schema + e.code().message()); + // Message format slightly changes between mongoc 2.0.0 and 2.1.0. (CDRIVER-5983) + // Invalid URI Schema, expecting 'mongodb://' or 'mongodb+srv://': ... + // -> + // Invalid URI scheme "mongo://". Expected one of "mongodb://" or "mongodb+srv://": ... + // https://github.com/mongodb/mongo-c-driver/commit/e388c29bc12b9d9568cde4fca6f95f6fba3289aa#diff-dbe89a1dfeb43b78de3fd2a755697ea837b1e6f6cc8fd589476e64d4fb873700R1985-R1987 + REQUIRE_THAT( + e.what(), + Catch::Matchers::ContainsSubstring("Invalid URI") && Catch::Matchers::ContainsSubstring("mongodb://") && + Catch::Matchers::ContainsSubstring("mongodb+srv://") && + Catch::Matchers::ContainsSubstring(e.code().message())); } }