Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions examples/mongocxx/mongodb.com/transactions_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,6 @@ int EXAMPLES_CDECL main() {
if (max_wire_version.type() != bsoncxx::type::k_int32) {
throw std::logic_error{"max wire version is not int32"};
}
if (max_wire_version.get_int32().value < 7) {
std::cerr << "Skipping: transactions example requires max wire version is >= 7" << std::endl;
return EXIT_SUCCESS;
}
}

for (auto const& example : examples) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ class bulk_write {
///
/// @return The number of documents that were modified.
///
/// @throws with server versions below 2.6 due to the field `nModified` not being returned.
///
MONGOCXX_ABI_EXPORT_CDECL(std::int32_t) modified_count() const;

///
Expand Down
8 changes: 2 additions & 6 deletions src/mongocxx/lib/mongocxx/v_noabi/mongocxx/collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,12 +1297,8 @@ void collection::_drop(
scoped_bson_t opts_bson{opts_doc.view()};
auto result = libmongoc::collection_drop_with_opts(_get_impl().collection_t, opts_bson.bson(), &error);

// Throw an exception if the command failed, unless the failure was due to a non-existent
// collection. We check for this failure using 'code', but we fall back to checking 'message'
// for old server versions (3.0 and earlier) that do not send a code with the command response.
if (!result &&
!(error.code == ::MONGOC_ERROR_COLLECTION_DOES_NOT_EXIST ||
bsoncxx::v_noabi::stdx::string_view{error.message} == bsoncxx::v_noabi::stdx::string_view{"ns not found"})) {
// Throw an exception if the command failed, unless the failure was due to a non-existent collection.
if (!result && error.code != MONGOC_ERROR_COLLECTION_DOES_NOT_EXIST) {
throw_exception<operation_exception>(error);
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/mongocxx/test/spec/gridfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,6 @@ TEST_CASE("GridFS spec automated tests", "[gridfs_spec]") {

client client{uri{}, test_util::add_test_server_api()};

// Because the GridFS spec tests use write commands that were only added to MongoDB in version
// 2.6, the tests will not run against any server versions older than that.
if (test_util::compare_versions(test_util::get_server_version(), "2.6") < 0) {
return;
}

auto cb = [&](std::string const& test_file) { run_gridfs_tests_in_file(test_file, &client); };

mongocxx::spec::run_tests_in_suite("GRIDFS_TESTS_PATH", cb);
Expand Down
14 changes: 0 additions & 14 deletions src/mongocxx/test/spec/unified_tests/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,6 @@ bool compatible_with_server(bsoncxx::array::element const& requirement) {
}
}

if (auto const csfle = requirement["csfle"]) {
// csfle: Optional boolean. If true, the tests MUST only run if the
// driver and server support Client-Side Field Level Encryption. A
// server supports CSFLE if it is version 4.2.0 or higher. If false,
// tests MUST only run if CSFLE is not enabled. If this field is
// omitted, there is no CSFLE requirement.
std::vector<int> const requires_at_least{4, 2, 0};
bool const is_csfle = csfle.get_bool().value;
if (is_csfle) {
if (!is_compatible_version(requires_at_least, expected)) {
return false;
}
}
}
return true;
}

Expand Down
2 changes: 0 additions & 2 deletions src/mongocxx/test/v_noabi/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,6 @@ TEST_CASE("integration tests for client metadata handshake feature") {

found_op = true;

std::string server_version = test_util::get_server_version();

REQUIRE(op_view["clientMetadata"]);
auto metadata = op_view["clientMetadata"].get_document();
auto metadata_view = metadata.view();
Expand Down
2 changes: 1 addition & 1 deletion src/mongocxx/test/v_noabi/client_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ std::int32_t compare_versions(std::string version1, std::string version2) {
return 0;
}

bool newer_than(std::string version) {
bool server_version_is_at_least(std::string version) {
auto server_version = get_server_version();
return (compare_versions(server_version, version) >= 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mongocxx/test/v_noabi/client_helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::int32_t compare_versions(std::string version1, std::string version2);
// Returns 'true' if the server version for the default client is at least 'version',
// returns 'false' otherwise.
//
bool newer_than(std::string version);
bool server_version_is_at_least(std::string version);

//
// Converts a hexadecimal string to an string of bytes.
Expand Down
5 changes: 0 additions & 5 deletions src/mongocxx/test/v_noabi/client_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,11 +822,6 @@ TEST_CASE("with_transaction", "[session]") {
// The following three tests are prose tests from the with_transaction spec.
SECTION("prose tests for with_transaction") {
SECTION("callback raises a custom error") {
// Multi-document transactions require server 4.2+.
if (compare_versions(get_server_version(), "4.2") < 0) {
SKIP("MongoDB server 4.2 or newer required");
}

// Test an operation_exception
REQUIRE_THROWS_MATCHES(
session.with_transaction([](client_session*) { throw operation_exception{{}, "The meaning of life"}; }),
Expand Down
66 changes: 4 additions & 62 deletions src/mongocxx/test/v_noabi/client_side_encryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,6 @@ TEST_CASE("Datakey and double encryption", "[client_side_encryption]") {

mongocxx::client setup_client{uri{}, test_util::add_test_server_api(client_opts)};

if (test_util::get_max_wire_version() < 8) {
// Automatic encryption requires wire version 8.
SKIP("max wire version is < 8");
}

// 2. Drop keyvault.datakeys and db.coll
_setup_drop_collections(setup_client);

Expand Down Expand Up @@ -579,11 +574,6 @@ TEST_CASE("External key vault", "[client_side_encryption]") {
test_util::add_test_server_api(),
};

if (test_util::get_max_wire_version() < 8) {
// Automatic encryption requires wire version 8.
SKIP("max wire version is < 8");
}

run_external_key_vault_test(true);
run_external_key_vault_test(false);
}
Expand All @@ -599,11 +589,6 @@ TEST_CASE("BSON size limits and batch splitting", "[client_side_encryption]") {
test_util::add_test_server_api(),
};

if (test_util::get_max_wire_version() < 8) {
// Automatic encryption requires wire version 8.
SKIP("max wire version is < 8");
}

// Load in json schema limits/limits-schema.json and limits/limits-key.json
auto limits_schema = _doc_from_file("/limits/limits-schema.json");
auto limits_key = _doc_from_file("/limits/limits-key.json");
Expand Down Expand Up @@ -757,11 +742,6 @@ TEST_CASE("Views are prohibited", "[client_side_encryption]") {
test_util::add_test_server_api(),
};

if (test_util::get_max_wire_version() < 8) {
// Automatic encryption requires wire version 8.
SKIP("max wire version is < 8");
}

// Using client, drop and create a view named db.view with an empty pipeline.
// E.g. using the command { "create": "view", "viewOn": "coll" }.
auto db = client["db"];
Expand Down Expand Up @@ -1096,11 +1076,6 @@ TEST_CASE("Corpus", "[client_side_encryption]") {
uri{},
test_util::add_test_server_api(),
};

if (test_util::get_max_wire_version() < 8) {
// Automatic encryption requires wire version 8.
SKIP("max wire version is < 8");
}
_run_corpus_test(true);
_run_corpus_test(false);
}
Expand Down Expand Up @@ -1217,11 +1192,6 @@ TEST_CASE("Custom endpoint", "[client_side_encryption]") {
test_util::add_test_server_api(),
};

if (test_util::get_max_wire_version() < 8) {
// Automatic encryption requires wire version 8.
SKIP("max wire version is < 8");
}

// Call client_encryption.createDataKey() with "aws" as the provider and the following
// masterKey:
// {
Expand Down Expand Up @@ -1560,11 +1530,6 @@ TEST_CASE("Bypass spawning mongocryptd", "[client_side_encryption]") {
test_util::add_test_server_api(),
};

if (test_util::get_max_wire_version() < 8) {
// Automatic encryption requires wire version 8.
SKIP("max wire version is < 8");
}

auto shared_lib_path = getenv("CRYPT_SHARED_LIB_PATH");

auto external_schema_file = _doc_from_file("/external/external-schema.json");
Expand Down Expand Up @@ -1703,11 +1668,6 @@ TEST_CASE("KMS TLS expired certificate", "[client_side_encryption]") {
SKIP("KMS TLS tests disabled (BUILD-14068)");
}

if (test_util::get_max_wire_version() < 8) {
// Automatic encryption requires wire version 8.
SKIP("max wire version is < 8");
}

options::client_encryption cse_opts;
_add_cse_opts(&cse_opts, &setup_client);
client_encryption client_encryption{std::move(cse_opts)};
Expand Down Expand Up @@ -1759,11 +1719,6 @@ TEST_CASE("KMS TLS wrong host certificate", "[client_side_encryption]") {
SKIP("KMS TLS tests disabled (BUILD-14068)");
}

if (test_util::get_max_wire_version() < 8) {
// Automatic encryption requires wire version 8.
SKIP("max wire version is < 8");
}

options::client_encryption cse_opts;
_add_cse_opts(&cse_opts, &setup_client);
client_encryption client_encryption{std::move(cse_opts)};
Expand Down Expand Up @@ -1868,11 +1823,6 @@ TEST_CASE("KMS TLS Options Tests", "[client_side_encryption][!mayfail]") {
SKIP("KMS TLS tests disabled (BUILD-14068)");
}

if (test_util::get_max_wire_version() < 8) {
// Automatic encryption requires wire version 8.
SKIP("max wire version is < 8");
}

auto client_encryption_no_client_cert =
make_prose_test_11_ce(&setup_client, "127.0.0.1:9002", "127.0.0.1:9002", "127.0.0.1:5698", with_certs::ca_only);
auto client_encryption_with_tls =
Expand Down Expand Up @@ -2120,7 +2070,7 @@ TEST_CASE("Explicit Encryption", "[client_side_encryption]") {
test_util::add_test_server_api(),
};

if (!test_util::newer_than("7.0")) {
if (!test_util::server_version_is_at_least("7.0")) {
SKIP("MongoDB server 7.0 or newer required");
}

Expand Down Expand Up @@ -2420,7 +2370,7 @@ TEST_CASE("Create Encrypted Collection", "[client_side_encryption]") {

mongocxx::client conn{mongocxx::uri{}, test_util::add_test_server_api()};

if (!test_util::newer_than("7.0")) {
if (!test_util::server_version_is_at_least("7.0")) {
SKIP("Explicit Encryption tests require MongoDB server 7.0+.");
}

Expand Down Expand Up @@ -2550,10 +2500,6 @@ TEST_CASE("Unique Index on keyAltNames", "[client_side_encryption]") {

CLIENT_SIDE_ENCRYPTION_ENABLED_OR_SKIP();

if (!test_util::newer_than("4.2")) {
SKIP("requires MongoDB server 4.2+");
}

// 1. Create a MongoClient object (referred to as client).
mongocxx::client client{mongocxx::uri{}, test_util::add_test_server_api()};

Expand Down Expand Up @@ -2691,10 +2637,6 @@ TEST_CASE("Custom Key Material Test", "[client_side_encryption]") {

CLIENT_SIDE_ENCRYPTION_ENABLED_OR_SKIP();

if (!test_util::newer_than("4.2")) {
SKIP("MongoDB server 4.2 or newer required");
}

// 1. Create a MongoClient object (referred to as client).
mongocxx::client client{mongocxx::uri{}, test_util::add_test_server_api()};

Expand Down Expand Up @@ -3037,7 +2979,7 @@ TEST_CASE("Range Explicit Encryption", "[client_side_encryption]") {
{
auto client = mongocxx::client(mongocxx::uri(), test_util::add_test_server_api());

if (!test_util::newer_than("8.0")) {
if (!test_util::server_version_is_at_least("8.0")) {
SKIP("MongoDB server 8.0 or newer required");
}

Expand Down Expand Up @@ -3443,7 +3385,7 @@ TEST_CASE("Range Explicit Encryption applies defaults", "[client_side_encryption
test_util::add_test_server_api(),
};

if (!test_util::newer_than("8.0")) {
if (!test_util::server_version_is_at_least("8.0")) {
SKIP("MongoDB server 8.0 or newer required");
}

Expand Down
20 changes: 4 additions & 16 deletions src/mongocxx/test/v_noabi/collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ TEST_CASE("CRUD functionality", "[driver::collection]") {
}

SECTION("update_one can take a pipeline", "[collection]") {
if (!test_util::newer_than("4.1.11")) {
if (!test_util::server_version_is_at_least("4.1.11")) {
SKIP("pipeline updates require 4.1.11");
}

Expand Down Expand Up @@ -1686,13 +1686,6 @@ TEST_CASE("CRUD functionality", "[driver::collection]") {
}

SECTION("merge") {
auto merge_version = "4.1.11";
auto server_version = test_util::get_server_version();
if (test_util::compare_versions(server_version, merge_version) < 0) {
// The server does not support $merge.
return;
}

collection coll = db["aggregation_merge"];
collection coll_out = db["aggregation_merge_out"];
coll.drop();
Expand Down Expand Up @@ -2222,7 +2215,7 @@ TEST_CASE("create_index tests", "[collection]") {

options::index options{};
options.unique(true);
if (test_util::newer_than("4.4"))
if (test_util::server_version_is_at_least("4.4"))
options.hidden(true);
options.expire_after(std::chrono::seconds(500));
options.name(index_name);
Expand All @@ -2239,7 +2232,7 @@ TEST_CASE("create_index tests", "[collection]") {
REQUIRE(unique_ele.type() == type::k_bool);
REQUIRE(unique_ele.get_bool() == options.unique().value());

if (test_util::newer_than("4.4")) {
if (test_util::server_version_is_at_least("4.4")) {
auto hidden_ele = index["hidden"];
REQUIRE(hidden_ele);
REQUIRE(hidden_ele.type() == type::k_bool);
Expand Down Expand Up @@ -2558,11 +2551,6 @@ TEST_CASE("Ensure that the WriteConcernError 'errInfo' object is propagated", "[

client mongodb_client{uri{}, test_util::add_test_server_api()};

if (test_util::get_topology() == "sharded" &&
test_util::compare_versions(test_util::get_server_version(), "4.1.0") < 0) {
SKIP("failCommand on mongos requires 4.1+");
}

using bsoncxx::builder::basic::sub_document;
auto err_info = builder::basic::document{};
err_info.append(kvp("writeConcern", [](sub_document sub_doc) {
Expand Down Expand Up @@ -2661,7 +2649,7 @@ TEST_CASE("expose writeErrors[].errInfo", "[collection]") {

auto mongodb_client = mongocxx::client(uri{}, client_opts);

if (!test_util::newer_than("5.0")) {
if (!test_util::server_version_is_at_least("5.0")) {
SKIP("test requires MongoDB server 5.0 or newer");
}

Expand Down
17 changes: 3 additions & 14 deletions src/mongocxx/test/v_noabi/index_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,9 @@ using bsoncxx::builder::basic::make_document;
using namespace mongocxx;

bool test_commands_enabled(client const& conn) {
auto result = conn["admin"].run_command(make_document(kvp("getParameter", 1), kvp("enableTestCommands", 1)));
auto result_view = result.view();

if (!result_view["enableTestCommands"]) {
return false;
}

auto server_version = test_util::get_server_version();

if (test_util::compare_versions(server_version, "3.2") >= 0) {
return result_view["enableTestCommands"].get_bool();
}

return result_view["enableTestCommands"].get_int32() == 1;
auto const result = conn["admin"].run_command(make_document(kvp("getParameter", 1), kvp("enableTestCommands", 1)));
auto const enable_test_commands = result.view()["enableTestCommands"];
return enable_test_commands ? enable_test_commands.get_bool() : false;
}

bool fail_with_max_timeout(client const& conn) {
Expand Down
6 changes: 0 additions & 6 deletions src/mongocxx/test/v_noabi/transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ TEST_CASE("Transaction tests", "[transactions]") {

if (!test_util::is_replica_set()) {
SKIP("transactions tests require replica set");
} else if (test_util::get_max_wire_version() < 7) {
SKIP("transactions tests require max wire version is >= 7");
}

// The test run in first 3 SECTIONs below
Expand Down Expand Up @@ -217,10 +215,6 @@ TEST_CASE("Transaction tests", "[transactions]") {
TEST_CASE("Transactions Mongos Pinning Prose Tests", "[transactions]") {
instance::current();

if (test_util::compare_versions(test_util::get_server_version(), "4.1.6") < 0) {
SKIP("requires server 4.1.6+");
}

if (test_util::get_topology() != "sharded") {
SKIP("requires sharded cluster topology");
}
Expand Down