diff options
author | mathisbessamdb <mathis.bessa@mongodb.com> | 2023-04-24 22:59:20 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-04-26 22:00:17 +0000 |
commit | 18659bb538d2ba53d5c93ac5a9df834c7cb7fe41 (patch) | |
tree | 25ab82a3e0c32f9710df132a45f36bf5d4f38ee6 /src/mongo/util | |
parent | 54c93d835e07dad55dd38f89928e3206a61a1234 (diff) | |
download | mongo-18659bb538d2ba53d5c93ac5a9df834c7cb7fe41.tar.gz |
SERVER-74493 Make DatabaseName constructors private
Diffstat (limited to 'src/mongo/util')
-rw-r--r-- | src/mongo/util/database_name_util.cpp | 7 | ||||
-rw-r--r-- | src/mongo/util/database_name_util.h | 3 | ||||
-rw-r--r-- | src/mongo/util/database_name_util_test.cpp | 24 |
3 files changed, 19 insertions, 15 deletions
diff --git a/src/mongo/util/database_name_util.cpp b/src/mongo/util/database_name_util.cpp index bd988f6c37c..bc2b999cc5e 100644 --- a/src/mongo/util/database_name_util.cpp +++ b/src/mongo/util/database_name_util.cpp @@ -89,7 +89,8 @@ std::string DatabaseNameUtil::serializeForCommands(const DatabaseName& dbName, } -DatabaseName parseDbNameFromStringExpectTenantIdInMultitenancyMode(StringData dbName) { +DatabaseName DatabaseNameUtil::parseDbNameFromStringExpectTenantIdInMultitenancyMode( + StringData dbName) { if (!gMultitenancySupport) { return DatabaseName(boost::none, dbName); } @@ -115,7 +116,7 @@ DatabaseName DatabaseNameUtil::deserialize(boost::optional<TenantId> tenantId, StringData db, const SerializationContext& context) { if (db.empty()) { - return DatabaseName(); + return DatabaseName(tenantId, ""); } if (!gMultitenancySupport) { @@ -144,7 +145,7 @@ DatabaseName DatabaseNameUtil::deserializeForStorage(boost::optional<TenantId> t return DatabaseName(std::move(tenantId), db); } - auto dbName = parseDbNameFromStringExpectTenantIdInMultitenancyMode(db); + auto dbName = DatabaseNameUtil::parseDbNameFromStringExpectTenantIdInMultitenancyMode(db); // TenantId could be prefixed, or passed in separately (or both) and namespace is always // constructed with the tenantId separately. if (tenantId != boost::none) { diff --git a/src/mongo/util/database_name_util.h b/src/mongo/util/database_name_util.h index f3668fd28dc..352f24a9dd8 100644 --- a/src/mongo/util/database_name_util.h +++ b/src/mongo/util/database_name_util.h @@ -104,6 +104,9 @@ public: boost::optional<TenantId> tenantId, StringData db, const SerializationContext& context = SerializationContext()); + +private: + static DatabaseName parseDbNameFromStringExpectTenantIdInMultitenancyMode(StringData dbName); }; } // namespace mongo diff --git a/src/mongo/util/database_name_util_test.cpp b/src/mongo/util/database_name_util_test.cpp index ef18f6e79cb..d573ee33434 100644 --- a/src/mongo/util/database_name_util_test.cpp +++ b/src/mongo/util/database_name_util_test.cpp @@ -164,25 +164,25 @@ TEST(DatabaseNameUtilTest, SerializeMissingExpectPrefix_CommandReply) { { // No prefix, no tenantId. // request --> { ns: database.coll } - auto dbName = DatabaseName(boost::none, dbnString); + auto dbName = DatabaseName::createDatabaseName_forTest(boost::none, dbnString); ASSERT_EQ(DatabaseNameUtil::serializeForCommands(dbName, ctxt_noTenantId), dbnString); } { // Has prefix, no tenantId. // request --> { ns: tenantId_database.coll } - auto dbName = DatabaseName(boost::none, dbnPrefixString); + auto dbName = DatabaseName::createDatabaseName_forTest(boost::none, dbnPrefixString); ASSERT_EQ(DatabaseNameUtil::serializeForCommands(dbName, ctxt_noTenantId), dbnPrefixString); } { // No prefix, has tenantId. // request --> { ns: database.coll, $tenant: tenantId } - auto dbName = DatabaseName(tenantId, dbnString); + auto dbName = DatabaseName::createDatabaseName_forTest(tenantId, dbnString); ASSERT_EQ(DatabaseNameUtil::serializeForCommands(dbName, ctxt_withTenantId), dbnString); } { // Has prefix, has tenantId. *** we shouldn't see this from Atlas Proxy // request --> { ns: tenantId_database.coll, $tenant: tenantId } - auto dbName = DatabaseName(tenantId, dbnPrefixString); + auto dbName = DatabaseName::createDatabaseName_forTest(tenantId, dbnPrefixString); ASSERT_EQ(DatabaseNameUtil::serializeForCommands(dbName, ctxt_withTenantId), dbnPrefixString); } @@ -205,25 +205,25 @@ TEST(DatabaseNameUtilTest, SerializeExpectPrefixFalse_CommandReply) { { // No prefix, no tenantId. // request --> { ns: database.coll, expectPrefix: false } - auto dbName = DatabaseName(boost::none, dbnString); + auto dbName = DatabaseName::createDatabaseName_forTest(boost::none, dbnString); ASSERT_EQ(DatabaseNameUtil::serializeForCommands(dbName, ctxt_noTenantId), dbnString); } { // Has prefix, no tenantId. *** we shouldn't see this from Atlas Proxy // request --> { ns: tenantId_database.coll, expectPrefix: false } - auto dbName = DatabaseName(boost::none, dbnPrefixString); + auto dbName = DatabaseName::createDatabaseName_forTest(boost::none, dbnPrefixString); ASSERT_EQ(DatabaseNameUtil::serializeForCommands(dbName, ctxt_noTenantId), dbnPrefixString); } { // No prefix, has tenantId. // request --> { ns: database.coll, $tenant: tenantId, expectPrefix: false } - auto dbName = DatabaseName(tenantId, dbnString); + auto dbName = DatabaseName::createDatabaseName_forTest(tenantId, dbnString); ASSERT_EQ(DatabaseNameUtil::serializeForCommands(dbName, ctxt_withTenantId), dbnString); } { // Has prefix, has tenantId. *** we shouldn't see this from Atlas Proxy // request --> { ns: tenantId_database.coll, $tenant: tenantId, expectPrefix: false } - auto dbName = DatabaseName(tenantId, dbnPrefixString); + auto dbName = DatabaseName::createDatabaseName_forTest(tenantId, dbnPrefixString); ASSERT_EQ(DatabaseNameUtil::serializeForCommands(dbName, ctxt_withTenantId), dbnPrefixString); } @@ -247,19 +247,19 @@ TEST(DatabaseNameUtilTest, SerializeExpectPrefixTrue_CommandReply) { { // No prefix, no tenantId. *** we shouldn't see this from Atlas Proxy // request --> { ns: database.coll, expectPrefix: true } - auto dbName = DatabaseName(boost::none, dbnString); + auto dbName = DatabaseName::createDatabaseName_forTest(boost::none, dbnString); ASSERT_EQ(DatabaseNameUtil::serializeForCommands(dbName, ctxt_noTenantId), dbnString); } { // Has prefix, no tenantId. // request --> { ns: tenantId_database.coll, expectPrefix: true } - auto dbName = DatabaseName(boost::none, dbnPrefixString); + auto dbName = DatabaseName::createDatabaseName_forTest(boost::none, dbnPrefixString); ASSERT_EQ(DatabaseNameUtil::serializeForCommands(dbName, ctxt_noTenantId), dbnPrefixString); } { // No prefix, has tenantId. *** we shouldn't see this from Atlas Proxy // request --> { ns: database.coll, $tenant: tenantId, expectPrefix: true } - auto dbName = DatabaseName(tenantId, dbnString); + auto dbName = DatabaseName::createDatabaseName_forTest(tenantId, dbnString); ASSERT_EQ(DatabaseNameUtil::serializeForCommands(dbName, ctxt_noTenantId), dbnPrefixString); } @@ -267,7 +267,7 @@ TEST(DatabaseNameUtilTest, SerializeExpectPrefixTrue_CommandReply) { // request --> { ns: tenantId_database.coll, $tenant: tenantId, expectPrefix: true } const std::string nsDoublePrefixString = str::stream() << tenantId.toString() << "_" << tenantId.toString() << "_" << dbnString; - auto dbName = DatabaseName(tenantId, dbnPrefixString); + auto dbName = DatabaseName::createDatabaseName_forTest(tenantId, dbnPrefixString); ASSERT_EQ(DatabaseNameUtil::serializeForCommands(dbName, ctxt_noTenantId), nsDoublePrefixString); } |