diff options
Diffstat (limited to 'src/mongo/db/update/update_driver_test.cpp')
-rw-r--r-- | src/mongo/db/update/update_driver_test.cpp | 51 |
1 files changed, 13 insertions, 38 deletions
diff --git a/src/mongo/db/update/update_driver_test.cpp b/src/mongo/db/update/update_driver_test.cpp index f64c1e353d3..1911c417f0a 100644 --- a/src/mongo/db/update/update_driver_test.cpp +++ b/src/mongo/db/update/update_driver_test.cpp @@ -52,38 +52,31 @@ using mongoutils::str::stream; TEST(Parse, Normal) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - UpdateDriver::Options opts(expCtx); - UpdateDriver driver(opts); + UpdateDriver driver(expCtx); std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_OK(driver.parse(fromjson("{$set:{a:1}}"), arrayFilters)); - ASSERT_EQUALS(driver.numMods(), 1U); ASSERT_FALSE(driver.isDocReplacement()); } TEST(Parse, MultiMods) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - UpdateDriver::Options opts(expCtx); - UpdateDriver driver(opts); + UpdateDriver driver(expCtx); std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_OK(driver.parse(fromjson("{$set:{a:1, b:1}}"), arrayFilters)); - ASSERT_EQUALS(driver.numMods(), 2U); ASSERT_FALSE(driver.isDocReplacement()); } TEST(Parse, MixingMods) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - UpdateDriver::Options opts(expCtx); - UpdateDriver driver(opts); + UpdateDriver driver(expCtx); std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_OK(driver.parse(fromjson("{$set:{a:1}, $unset:{b:1}}"), arrayFilters)); - ASSERT_EQUALS(driver.numMods(), 2U); ASSERT_FALSE(driver.isDocReplacement()); } TEST(Parse, ObjectReplacment) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - UpdateDriver::Options opts(expCtx); - UpdateDriver driver(opts); + UpdateDriver driver(expCtx); std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_OK(driver.parse(fromjson("{obj: \"obj replacement\"}"), arrayFilters)); ASSERT_TRUE(driver.isDocReplacement()); @@ -91,8 +84,7 @@ TEST(Parse, ObjectReplacment) { TEST(Parse, EmptyMod) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - UpdateDriver::Options opts(expCtx); - UpdateDriver driver(opts); + UpdateDriver driver(expCtx); std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_THROWS_CODE_AND_WHAT( driver.parse(fromjson("{$set:{}}"), arrayFilters).transitional_ignore(), @@ -103,8 +95,7 @@ TEST(Parse, EmptyMod) { TEST(Parse, WrongMod) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - UpdateDriver::Options opts(expCtx); - UpdateDriver driver(opts); + UpdateDriver driver(expCtx); std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_THROWS_CODE_AND_WHAT( driver.parse(fromjson("{$xyz:{a:1}}"), arrayFilters).transitional_ignore(), @@ -115,8 +106,7 @@ TEST(Parse, WrongMod) { TEST(Parse, WrongType) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - UpdateDriver::Options opts(expCtx); - UpdateDriver driver(opts); + UpdateDriver driver(expCtx); std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_THROWS_CODE_AND_WHAT( driver.parse(fromjson("{$set:[{a:1}]}"), arrayFilters).transitional_ignore(), @@ -128,8 +118,7 @@ TEST(Parse, WrongType) { TEST(Parse, ModsWithLaterObjReplacement) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - UpdateDriver::Options opts(expCtx); - UpdateDriver driver(opts); + UpdateDriver driver(expCtx); std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_THROWS_CODE_AND_WHAT( driver.parse(fromjson("{$set:{a:1}, obj: \"obj replacement\"}"), arrayFilters) @@ -141,11 +130,9 @@ TEST(Parse, ModsWithLaterObjReplacement) { TEST(Parse, SetOnInsert) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - UpdateDriver::Options opts(expCtx); - UpdateDriver driver(opts); + UpdateDriver driver(expCtx); std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_OK(driver.parse(fromjson("{$setOnInsert:{a:1}}"), arrayFilters)); - ASSERT_EQUALS(driver.numMods(), 1U); ASSERT_FALSE(driver.isDocReplacement()); } @@ -153,27 +140,17 @@ TEST(Collator, SetCollationUpdatesModifierInterfaces) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); CollatorInterfaceMock reverseStringCollator(CollatorInterfaceMock::MockType::kReverseString); BSONObj updateDocument = fromjson("{$max: {a: 'abd'}}"); - UpdateDriver::Options opts(expCtx); - UpdateDriver driver(opts); + UpdateDriver driver(expCtx); std::map<StringData, std::unique_ptr<ExpressionWithPlaceholder>> arrayFilters; ASSERT_OK(driver.parse(updateDocument, arrayFilters)); - ASSERT_EQUALS(driver.numMods(), 1U); - const BSONObj original; const bool validateForStorage = true; const FieldRefSet emptyImmutablePaths; bool modified = false; mutablebson::Document doc(fromjson("{a: 'cba'}")); driver.setCollator(&reverseStringCollator); - driver - .update(StringData(), - original, - &doc, - validateForStorage, - emptyImmutablePaths, - nullptr, - &modified) + driver.update(StringData(), &doc, validateForStorage, emptyImmutablePaths, nullptr, &modified) .transitional_ignore(); ASSERT_TRUE(modified); @@ -190,10 +167,8 @@ class CreateFromQueryFixture : public mongo::unittest::Test { public: CreateFromQueryFixture() : _opCtx(_serviceContext.makeOperationContext()), - _driverOps(new UpdateDriver( - UpdateDriver::Options(new ExpressionContext(_opCtx.get(), nullptr)))), - _driverRepl(new UpdateDriver( - UpdateDriver::Options(new ExpressionContext(_opCtx.get(), nullptr)))) { + _driverOps(new UpdateDriver(new ExpressionContext(_opCtx.get(), nullptr))), + _driverRepl(new UpdateDriver(new ExpressionContext(_opCtx.get(), nullptr))) { _driverOps->parse(fromjson("{$set:{'_':1}}"), _arrayFilters).transitional_ignore(); _driverRepl->parse(fromjson("{}"), _arrayFilters).transitional_ignore(); } |