summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/getmore_request_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/query/getmore_request_test.cpp')
-rw-r--r--src/mongo/db/query/getmore_request_test.cpp284
1 files changed, 149 insertions, 135 deletions
diff --git a/src/mongo/db/query/getmore_request_test.cpp b/src/mongo/db/query/getmore_request_test.cpp
index bd2f8c8b242..abb50b693f6 100644
--- a/src/mongo/db/query/getmore_request_test.cpp
+++ b/src/mongo/db/query/getmore_request_test.cpp
@@ -37,138 +37,152 @@
namespace {
- using namespace mongo;
-
- TEST(GetMoreRequestTest, parseFromBSONEmptyCommandObject) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON("db", BSONObj());
- ASSERT_NOT_OK(result.getStatus());
- ASSERT_EQUALS(ErrorCodes::FailedToParse, result.getStatus().code());
- }
-
- TEST(GetMoreRequestTest, parseFromBSONCursorIdNotNumeric) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << "not a number" <<
- "collection" << "coll"));
- ASSERT_NOT_OK(result.getStatus());
- ASSERT_EQUALS(ErrorCodes::TypeMismatch, result.getStatus().code());
- }
-
- TEST(GetMoreRequestTest, parseFromBSONCursorIdNotLongLong) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << "not a number" <<
- "collection" << 123));
- ASSERT_NOT_OK(result.getStatus());
- ASSERT_EQUALS(ErrorCodes::TypeMismatch, result.getStatus().code());
- }
-
- TEST(GetMoreRequestTest, parseFromBSONMissingCollection) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << CursorId(123)));
- ASSERT_NOT_OK(result.getStatus());
- ASSERT_EQUALS(ErrorCodes::FailedToParse, result.getStatus().code());
- }
-
- TEST(GetMoreRequestTest, parseFromBSONCollectionNotString) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << CursorId(123) << "collection" << 456));
- ASSERT_NOT_OK(result.getStatus());
- ASSERT_EQUALS(ErrorCodes::TypeMismatch, result.getStatus().code());
- }
-
- TEST(GetMoreRequestTest, parseFromBSONBatchSizeNotInteger) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << CursorId(123) <<
- "collection" << "coll" <<
- "batchSize" << "not a number"));
- ASSERT_NOT_OK(result.getStatus());
- ASSERT_EQUALS(ErrorCodes::TypeMismatch, result.getStatus().code());
- }
-
- TEST(GetMoreRequestTest, parseFromBSONInvalidCursorId) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << CursorId(0) << "collection" << "coll"));
- ASSERT_NOT_OK(result.getStatus());
- ASSERT_EQUALS(ErrorCodes::BadValue, result.getStatus().code());
- }
-
- TEST(GetMoreRequestTest, parseFromBSONNegativeCursorId) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << CursorId(-123) << "collection" << "coll"));
- ASSERT_OK(result.getStatus());
- ASSERT_EQUALS("db.coll", result.getValue().nss.toString());
- ASSERT_EQUALS(CursorId(-123), result.getValue().cursorid);
- ASSERT_FALSE(result.getValue().batchSize);
- }
-
- TEST(GetMoreRequestTest, parseFromBSONUnrecognizedFieldName) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << CursorId(123) <<
- "collection" << "coll" <<
- "unknown_field" << 1));
- ASSERT_NOT_OK(result.getStatus());
- ASSERT_EQUALS(ErrorCodes::FailedToParse, result.getStatus().code());
- }
-
- TEST(GetMoreRequestTest, parseFromBSONInvalidBatchSize) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << CursorId(123) << "collection" << "coll" << "batchSize" << -1));
- ASSERT_NOT_OK(result.getStatus());
- ASSERT_EQUALS(ErrorCodes::BadValue, result.getStatus().code());
- }
-
- TEST(GetMoreRequestTest, parseFromBSONInvalidBatchSizeOfZero) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << CursorId(123) << "collection" << "coll" << "batchSize" << 0));
- ASSERT_NOT_OK(result.getStatus());
- ASSERT_EQUALS(ErrorCodes::BadValue, result.getStatus().code());
- }
-
- TEST(GetMoreRequestTest, parseFromBSONNoBatchSize) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << CursorId(123) << "collection" << "coll"));
- ASSERT_OK(result.getStatus());
- ASSERT_EQUALS("db.coll", result.getValue().nss.toString());
- ASSERT_EQUALS(CursorId(123), result.getValue().cursorid);
- ASSERT_FALSE(result.getValue().batchSize);
- }
-
- TEST(GetMoreRequestTest, parseFromBSONBatchSizeProvided) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << CursorId(123) << "collection" << "coll" << "batchSize" << 200));
- ASSERT_EQUALS("db.coll", result.getValue().nss.toString());
- ASSERT_EQUALS(CursorId(123), result.getValue().cursorid);
- ASSERT(result.getValue().batchSize);
- ASSERT_EQUALS(200, *result.getValue().batchSize);
- }
-
- TEST(GetMoreRequestTest, parseFromBSONIgnoreDollarPrefixedFields) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << CursorId(123) << "collection" << "coll" << "$foo" << "bar"));
- ASSERT_OK(result.getStatus());
- ASSERT_EQUALS("db.coll", result.getValue().nss.toString());
- ASSERT_EQUALS(CursorId(123), result.getValue().cursorid);
- }
-
- TEST(GetMoreRequestTest, parseFromBSONIgnoreMaxTimeMS) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "db",
- BSON("getMore" << CursorId(123) << "collection" << "coll" << "maxTimeMS" << 100));
- ASSERT_OK(result.getStatus());
- ASSERT_EQUALS("db.coll", result.getValue().nss.toString());
- ASSERT_EQUALS(CursorId(123), result.getValue().cursorid);
- }
-
-} // namespace
+using namespace mongo;
+
+TEST(GetMoreRequestTest, parseFromBSONEmptyCommandObject) {
+ StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON("db", BSONObj());
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQUALS(ErrorCodes::FailedToParse, result.getStatus().code());
+}
+
+TEST(GetMoreRequestTest, parseFromBSONCursorIdNotNumeric) {
+ StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON("db",
+ BSON("getMore"
+ << "not a number"
+ << "collection"
+ << "coll"));
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQUALS(ErrorCodes::TypeMismatch, result.getStatus().code());
+}
+
+TEST(GetMoreRequestTest, parseFromBSONCursorIdNotLongLong) {
+ StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON("db",
+ BSON("getMore"
+ << "not a number"
+ << "collection" << 123));
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQUALS(ErrorCodes::TypeMismatch, result.getStatus().code());
+}
+
+TEST(GetMoreRequestTest, parseFromBSONMissingCollection) {
+ StatusWith<GetMoreRequest> result =
+ GetMoreRequest::parseFromBSON("db", BSON("getMore" << CursorId(123)));
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQUALS(ErrorCodes::FailedToParse, result.getStatus().code());
+}
+
+TEST(GetMoreRequestTest, parseFromBSONCollectionNotString) {
+ StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
+ "db", BSON("getMore" << CursorId(123) << "collection" << 456));
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQUALS(ErrorCodes::TypeMismatch, result.getStatus().code());
+}
+
+TEST(GetMoreRequestTest, parseFromBSONBatchSizeNotInteger) {
+ StatusWith<GetMoreRequest> result =
+ GetMoreRequest::parseFromBSON("db",
+ BSON("getMore" << CursorId(123) << "collection"
+ << "coll"
+ << "batchSize"
+ << "not a number"));
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQUALS(ErrorCodes::TypeMismatch, result.getStatus().code());
+}
+
+TEST(GetMoreRequestTest, parseFromBSONInvalidCursorId) {
+ StatusWith<GetMoreRequest> result =
+ GetMoreRequest::parseFromBSON("db",
+ BSON("getMore" << CursorId(0) << "collection"
+ << "coll"));
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQUALS(ErrorCodes::BadValue, result.getStatus().code());
+}
+
+TEST(GetMoreRequestTest, parseFromBSONNegativeCursorId) {
+ StatusWith<GetMoreRequest> result =
+ GetMoreRequest::parseFromBSON("db",
+ BSON("getMore" << CursorId(-123) << "collection"
+ << "coll"));
+ ASSERT_OK(result.getStatus());
+ ASSERT_EQUALS("db.coll", result.getValue().nss.toString());
+ ASSERT_EQUALS(CursorId(-123), result.getValue().cursorid);
+ ASSERT_FALSE(result.getValue().batchSize);
+}
+
+TEST(GetMoreRequestTest, parseFromBSONUnrecognizedFieldName) {
+ StatusWith<GetMoreRequest> result =
+ GetMoreRequest::parseFromBSON("db",
+ BSON("getMore" << CursorId(123) << "collection"
+ << "coll"
+ << "unknown_field" << 1));
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQUALS(ErrorCodes::FailedToParse, result.getStatus().code());
+}
+
+TEST(GetMoreRequestTest, parseFromBSONInvalidBatchSize) {
+ StatusWith<GetMoreRequest> result =
+ GetMoreRequest::parseFromBSON("db",
+ BSON("getMore" << CursorId(123) << "collection"
+ << "coll"
+ << "batchSize" << -1));
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQUALS(ErrorCodes::BadValue, result.getStatus().code());
+}
+
+TEST(GetMoreRequestTest, parseFromBSONInvalidBatchSizeOfZero) {
+ StatusWith<GetMoreRequest> result =
+ GetMoreRequest::parseFromBSON("db",
+ BSON("getMore" << CursorId(123) << "collection"
+ << "coll"
+ << "batchSize" << 0));
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQUALS(ErrorCodes::BadValue, result.getStatus().code());
+}
+
+TEST(GetMoreRequestTest, parseFromBSONNoBatchSize) {
+ StatusWith<GetMoreRequest> result =
+ GetMoreRequest::parseFromBSON("db",
+ BSON("getMore" << CursorId(123) << "collection"
+ << "coll"));
+ ASSERT_OK(result.getStatus());
+ ASSERT_EQUALS("db.coll", result.getValue().nss.toString());
+ ASSERT_EQUALS(CursorId(123), result.getValue().cursorid);
+ ASSERT_FALSE(result.getValue().batchSize);
+}
+
+TEST(GetMoreRequestTest, parseFromBSONBatchSizeProvided) {
+ StatusWith<GetMoreRequest> result =
+ GetMoreRequest::parseFromBSON("db",
+ BSON("getMore" << CursorId(123) << "collection"
+ << "coll"
+ << "batchSize" << 200));
+ ASSERT_EQUALS("db.coll", result.getValue().nss.toString());
+ ASSERT_EQUALS(CursorId(123), result.getValue().cursorid);
+ ASSERT(result.getValue().batchSize);
+ ASSERT_EQUALS(200, *result.getValue().batchSize);
+}
+
+TEST(GetMoreRequestTest, parseFromBSONIgnoreDollarPrefixedFields) {
+ StatusWith<GetMoreRequest> result =
+ GetMoreRequest::parseFromBSON("db",
+ BSON("getMore" << CursorId(123) << "collection"
+ << "coll"
+ << "$foo"
+ << "bar"));
+ ASSERT_OK(result.getStatus());
+ ASSERT_EQUALS("db.coll", result.getValue().nss.toString());
+ ASSERT_EQUALS(CursorId(123), result.getValue().cursorid);
+}
+
+TEST(GetMoreRequestTest, parseFromBSONIgnoreMaxTimeMS) {
+ StatusWith<GetMoreRequest> result =
+ GetMoreRequest::parseFromBSON("db",
+ BSON("getMore" << CursorId(123) << "collection"
+ << "coll"
+ << "maxTimeMS" << 100));
+ ASSERT_OK(result.getStatus());
+ ASSERT_EQUALS("db.coll", result.getValue().nss.toString());
+ ASSERT_EQUALS(CursorId(123), result.getValue().cursorid);
+}
+
+} // namespace