Skip to content

Commit 0204b35

Browse files
committed
minor: add support for testing on MonogDB 2.0
1 parent d16dfa4 commit 0204b35

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

src/mongo/client/examples/aggregation.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ int main(int argc, char* argv[]) {
4949
conn.connect(std::string("localhost:").append(port));
5050
conn.dropCollection("test.test");
5151

52+
// Don't run on MongoDB < 2.2
53+
BSONObj cmdResult;
54+
conn.runCommand("admin", BSON("buildinfo" << true), cmdResult);
55+
std::vector<BSONElement> versionArray = cmdResult["versionArray"].Array();
56+
if (versionArray[0].Int() < 2 || versionArray[1].Int() < 2)
57+
return EXIT_SUCCESS;
58+
5259
conn.insert("test.test", BSON("x" << 0));
5360
conn.insert("test.test", BSON("x" << 1));
5461
conn.insert("test.test", BSON("x" << 1));

src/mongo/unittest/dbclient_test.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -814,25 +814,27 @@ namespace {
814814
}
815815

816816
TEST_F(DBClientTest, Aggregate) {
817-
BSONObj doc = BSON("hello" << "world");
817+
if (serverGTE(&c, 2, 2)) {
818+
BSONObj doc = BSON("hello" << "world");
818819

819-
BSONObj pipeline = BSON("0" << BSON("$match" << doc));
820+
BSONObj pipeline = BSON("0" << BSON("$match" << doc));
820821

821-
c.insert(TEST_NS, doc);
822-
c.insert(TEST_NS, doc);
822+
c.insert(TEST_NS, doc);
823+
c.insert(TEST_NS, doc);
823824

824-
std::auto_ptr<DBClientCursor> cursor = c.aggregate(TEST_NS, pipeline);
825-
ASSERT_TRUE(cursor.get());
825+
std::auto_ptr<DBClientCursor> cursor = c.aggregate(TEST_NS, pipeline);
826+
ASSERT_TRUE(cursor.get());
826827

827-
for (int i = 0; i < 2; i++) {
828-
ASSERT_TRUE(cursor->more());
828+
for (int i = 0; i < 2; i++) {
829+
ASSERT_TRUE(cursor->more());
829830

830-
BSONObj result = cursor->next();
831-
ASSERT_TRUE(result.valid());
832-
ASSERT_EQUALS(result["hello"].String(), "world");
833-
}
831+
BSONObj result = cursor->next();
832+
ASSERT_TRUE(result.valid());
833+
ASSERT_EQUALS(result["hello"].String(), "world");
834+
}
834835

835-
ASSERT_FALSE(cursor->more());
836+
ASSERT_FALSE(cursor->more());
837+
}
836838
}
837839

838840
TEST_F(DBClientTest, CreateCollection) {
@@ -846,7 +848,9 @@ namespace {
846848

847849
bool server26plus = serverGTE(&c, 2, 6);
848850

849-
ASSERT_EQUALS(info.getIntField("userFlags"), server26plus ? 1 : 0);
851+
if (serverGTE(&c, 2, 2)) {
852+
ASSERT_EQUALS(info.getIntField("userFlags"), server26plus ? 1 : 0);
853+
}
850854
ASSERT_EQUALS(info.getIntField("nindexes"), 1);
851855
}
852856

@@ -859,7 +863,9 @@ namespace {
859863
BSONObj info;
860864
ASSERT_TRUE(c.runCommand(TEST_DB, BSON("collstats" << TEST_COLL), info));
861865

862-
ASSERT_EQUALS(info.getIntField("userFlags"), 0);
866+
if (serverGTE(&c, 2, 2)) {
867+
ASSERT_EQUALS(info.getIntField("userFlags"), 0);
868+
}
863869
ASSERT_EQUALS(info.getIntField("nindexes"), 0);
864870
}
865871

0 commit comments

Comments
 (0)