summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/querytests.cpp
diff options
context:
space:
mode:
authorVesselina Ratcheva <vesselina.ratcheva@mongodb.com>2019-10-17 17:24:51 +0000
committerevergreen <evergreen@mongodb.com>2019-10-17 17:24:51 +0000
commitfff3ebaaa26b97674d19234344ea30817ac6dd4e (patch)
treeeeb14aae7a936b0084136b21c161260a2c1f63a7 /src/mongo/dbtests/querytests.cpp
parentd78ab05ea802c80e10ed81a177bc0f7ba5e643a4 (diff)
downloadmongo-fff3ebaaa26b97674d19234344ea30817ac6dd4e.tar.gz
SERVER-43272 Implement getDatabaseInfos method (listDatabases) in DBClient
Diffstat (limited to 'src/mongo/dbtests/querytests.cpp')
-rw-r--r--src/mongo/dbtests/querytests.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index 22cd9256808..97e8ee011db 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -1822,6 +1822,61 @@ public:
}
};
+class GetDatabaseInfosTest : public CollectionBase {
+public:
+ GetDatabaseInfosTest() : CollectionBase("GetDatabaseInfosTest") {}
+
+ void run() {
+ const char* ns1 = "unittestsdb1.querytests.coll1";
+ {
+ Lock::GlobalWrite lk(&_opCtx);
+ OldClientContext context(&_opCtx, ns1);
+ WriteUnitOfWork wunit(&_opCtx);
+ context.db()->createCollection(&_opCtx, NamespaceString(ns1));
+ wunit.commit();
+ }
+ insert(ns1, BSON("a" << 1));
+ auto dbInfos = _client.getDatabaseInfos(BSONObj(), true /*nameOnly*/);
+ checkNewDBInResults(dbInfos, 1);
+
+
+ const char* ns2 = "unittestsdb2.querytests.coll2";
+ {
+ Lock::GlobalWrite lk(&_opCtx);
+ OldClientContext context(&_opCtx, ns2);
+ WriteUnitOfWork wunit(&_opCtx);
+ context.db()->createCollection(&_opCtx, NamespaceString(ns2));
+ wunit.commit();
+ }
+ insert(ns2, BSON("b" << 2));
+ dbInfos = _client.getDatabaseInfos(BSONObj(), true /*nameOnly*/);
+ checkNewDBInResults(dbInfos, 2);
+
+
+ const char* ns3 = "unittestsdb3.querytests.coll3";
+ {
+ Lock::GlobalWrite lk(&_opCtx);
+ OldClientContext context(&_opCtx, ns3);
+ WriteUnitOfWork wunit(&_opCtx);
+ context.db()->createCollection(&_opCtx, NamespaceString(ns3));
+ wunit.commit();
+ }
+ insert(ns3, BSON("c" << 3));
+ dbInfos = _client.getDatabaseInfos(BSONObj(), true /*nameOnly*/);
+ checkNewDBInResults(dbInfos, 3);
+ }
+
+ void checkNewDBInResults(const std::vector<BSONObj> results, const int dbNum) {
+ std::string target = "unittestsdb" + std::to_string(dbNum);
+ for (auto res : results) {
+ if (res["name"].str() == target) {
+ return;
+ }
+ }
+ ASSERT(false); // Should not hit this unless we failed to find the database.
+ }
+};
+
class CollectionInternalBase : public CollectionBase {
public:
CollectionInternalBase(const char* nsLeaf)
@@ -1985,6 +2040,8 @@ public:
add<WhatsMyUri>();
add<QueryByUuid>();
add<GetIndexSpecsByUUID>();
+ add<CountByUUID>();
+ add<GetDatabaseInfosTest>();
add<Exhaust>();
add<QueryReadsAll>();
add<queryobjecttests::names1>();