summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_parser_test.cpp
diff options
context:
space:
mode:
authorNick Zolnierz <nicholas.zolnierz@mongodb.com>2018-03-20 17:56:02 -0400
committerNick Zolnierz <nicholas.zolnierz@mongodb.com>2018-03-20 17:57:31 -0400
commit2682dbfb28324406f6eded1f22f6e342a392ff13 (patch)
tree1a12a708dd45c159ce3a803090a7397e40fc68b7 /src/mongo/db/matcher/expression_parser_test.cpp
parent152e55c697613b0d99c619e9569fd6e57c303d2f (diff)
downloadmongo-2682dbfb28324406f6eded1f22f6e342a392ff13.tar.gz
Revert "SERVER-30005: remove $isolated/$atomic option"
This reverts commit cd950b113ee0d00e88036b2fe6306866c7ba27f9.
Diffstat (limited to 'src/mongo/db/matcher/expression_parser_test.cpp')
-rw-r--r--src/mongo/db/matcher/expression_parser_test.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_parser_test.cpp b/src/mongo/db/matcher/expression_parser_test.cpp
index d2bcd91a1b4..4343cf60403 100644
--- a/src/mongo/db/matcher/expression_parser_test.cpp
+++ b/src/mongo/db/matcher/expression_parser_test.cpp
@@ -65,6 +65,56 @@ TEST(MatchExpressionParserTest, Multiple1) {
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5 << "y" << 4)));
}
+TEST(AtomicMatchExpressionTest, AtomicOperatorSuccessfullyParsesWhenFeatureBitIsSet) {
+ auto query = BSON("x" << 5 << "$atomic" << 1);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ auto result = MatchExpressionParser::parse(
+ query, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::AllowedFeatures::kIsolated);
+ ASSERT_OK(result.getStatus());
+}
+
+TEST(AtomicMatchExpressionTest, AtomicOperatorFailsToParseIfNotTopLevel) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ auto query = BSON("x" << 5 << "y" << BSON("$atomic" << 1));
+ auto result = MatchExpressionParser::parse(
+ query, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::AllowedFeatures::kIsolated);
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQ(ErrorCodes::BadValue, result.getStatus());
+}
+
+TEST(AtomicMatchExpressionTest, AtomicOperatorFailsToParseIfFeatureBitIsNotSet) {
+ auto query = BSON("x" << 5 << "$atomic" << 1);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ auto result = MatchExpressionParser::parse(query, expCtx);
+ ASSERT_EQ(ErrorCodes::QueryFeatureNotAllowed, result.getStatus());
+}
+
+TEST(IsolatedMatchExpressionTest, IsolatedOperatorSuccessfullyParsesWhenFeatureBitIsSet) {
+ auto query = BSON("x" << 5 << "$isolated" << 1);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ auto result = MatchExpressionParser::parse(
+ query, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::AllowedFeatures::kIsolated);
+ ASSERT_OK(result.getStatus());
+}
+
+TEST(IsolatedMatchExpressionTest, IsolatedOperatorFailsToParseIfFeatureBitIsNotSet) {
+ // Query parsing fails if $isolated is not in the allowed feature set.
+ auto query = BSON("x" << 5 << "$isolated" << 1);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ auto result = MatchExpressionParser::parse(query, expCtx);
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQ(ErrorCodes::QueryFeatureNotAllowed, result.getStatus());
+}
+
+TEST(IsolatedMatchExpressionTest, IsolatedOperatorFailsToParseIfNotTopLevel) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ auto query = BSON("x" << 5 << "y" << BSON("$isolated" << 1));
+ auto result = MatchExpressionParser::parse(
+ query, expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::AllowedFeatures::kIsolated);
+ ASSERT_NOT_OK(result.getStatus());
+ ASSERT_EQ(ErrorCodes::BadValue, result.getStatus());
+}
+
TEST(MatchExpressionParserTest, MinDistanceWithoutNearFailsToParse) {
BSONObj query = fromjson("{loc: {$minDistance: 10}}");
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());