diff options
author | Spencer Jackson <spencer.jackson@mongodb.com> | 2016-12-12 15:37:57 -0500 |
---|---|---|
committer | Spencer Jackson <spencer.jackson@mongodb.com> | 2016-12-15 18:15:23 -0500 |
commit | 88dd11b030dbbc47332d42d431a40865cc534435 (patch) | |
tree | db6aa7f004aa8616c986b918fc4f53d1f4e9e05b /src | |
parent | d6a23485995c3351a8c797bc4d74a55edbbce8fe (diff) | |
download | mongo-88dd11b030dbbc47332d42d431a40865cc534435.tar.gz |
SERVER-27385: Add dbtest asserting that {rolesInfo: 1} returns no duplicate fields
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/dbtests/commandtests.cpp | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/src/mongo/dbtests/commandtests.cpp b/src/mongo/dbtests/commandtests.cpp index db5d6227452..a310184db78 100644 --- a/src/mongo/dbtests/commandtests.cpp +++ b/src/mongo/dbtests/commandtests.cpp @@ -28,6 +28,8 @@ #include "mongo/platform/basic.h" +#include <unordered_set> + #include "mongo/db/client.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/dbdirectclient.h" @@ -40,6 +42,30 @@ namespace CommandTests { using std::string; +/** + * Default suite base, unless otherwise overridden in test specific namespace. + */ +class Base { +public: + Base() : db(&_txn) { + db.dropCollection(ns()); + } + + const char* ns() { + return "test.testCollection"; + } + const char* nsDb() { + return "test"; + } + const char* nsColl() { + return "testCollection"; + } + + const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); + OperationContext& _txn = *_txnPtr; + DBDirectClient db; +}; + // one namespace per command namespace FileMD5 { struct Base { @@ -112,27 +138,6 @@ namespace SymbolArgument { // This is a historical quirk that we shall support until corrected versions of the Ruby driver // can be distributed. Retain these tests until MongoDB 3.0 -class Base { -public: - Base() : db(&_txn) { - db.dropCollection(ns()); - } - - const char* ns() { - return "test.symbolarg"; - } - const char* nsDb() { - return "test"; - } - const char* nsColl() { - return "symbolarg"; - } - - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; - DBDirectClient db; -}; - class Drop : Base { public: void run() { @@ -302,7 +307,25 @@ public: } }; -} // SymbolArgument +} // namespace SymbolArgument + +/** + * Tests that the 'rolesInfo' command does not return duplicate field names. + */ +class RolesInfoShouldNotReturnDuplicateFieldNames : Base { +public: + void run() { + BSONObj result; + bool ok = db.runCommand(nsDb(), BSON("rolesInfo" << 1), result); + ASSERT(ok); + + stdx::unordered_set<std::string> observedFields; + for (const auto& field : result) { + ASSERT(observedFields.find(field) == observedFields.end()); + observedFields.insert(field); + } + } +}; class All : public Suite { public: @@ -319,6 +342,7 @@ public: add<SymbolArgument::GeoSearch>(); add<SymbolArgument::CreateIndexWithNoKey>(); add<SymbolArgument::CreateIndexWithDuplicateKey>(); + add<RolesInfoShouldNotReturnDuplicateFieldNames>(); } }; |