diff options
Diffstat (limited to 'src/mongo/db/update/pull_node_test.cpp')
-rw-r--r-- | src/mongo/db/update/pull_node_test.cpp | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/src/mongo/db/update/pull_node_test.cpp b/src/mongo/db/update/pull_node_test.cpp index 6c191f0ed99..b9092a98927 100644 --- a/src/mongo/db/update/pull_node_test.cpp +++ b/src/mongo/db/update/pull_node_test.cpp @@ -139,7 +139,7 @@ TEST_F(PullNodeTest, TargetNotFound) { mutablebson::Document doc(fromjson("{}")); setPathToCreate("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root())); + auto result = node.apply(getApplyParams(doc.root()), getUpdateNodeApplyParams()); ASSERT_TRUE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{}"), doc); @@ -156,10 +156,11 @@ TEST_F(PullNodeTest, ApplyToStringFails) { mutablebson::Document doc(fromjson("{a: 'foo'}")); setPathTaken("a"); addIndexedPath("a"); - ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - AssertionException, - ErrorCodes::BadValue, - "Cannot apply $pull to a non-array value"); + ASSERT_THROWS_CODE_AND_WHAT( + node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()), + AssertionException, + ErrorCodes::BadValue, + "Cannot apply $pull to a non-array value"); } TEST_F(PullNodeTest, ApplyToObjectFails) { @@ -171,10 +172,11 @@ TEST_F(PullNodeTest, ApplyToObjectFails) { mutablebson::Document doc(fromjson("{a: {foo: 'bar'}}")); setPathTaken("a"); addIndexedPath("a"); - ASSERT_THROWS_CODE_AND_WHAT(node.apply(getApplyParams(doc.root()["a"])), - AssertionException, - ErrorCodes::BadValue, - "Cannot apply $pull to a non-array value"); + ASSERT_THROWS_CODE_AND_WHAT( + node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()), + AssertionException, + ErrorCodes::BadValue, + "Cannot apply $pull to a non-array value"); } TEST_F(PullNodeTest, ApplyToNonViablePathFails) { @@ -188,7 +190,7 @@ TEST_F(PullNodeTest, ApplyToNonViablePathFails) { setPathTaken("a"); addIndexedPath("a"); ASSERT_THROWS_CODE_AND_WHAT( - node.apply(getApplyParams(doc.root()["a"])), + node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()), AssertionException, ErrorCodes::PathNotViable, "Cannot use the part (b) of (a.b) to traverse the element ({a: 1})"); @@ -204,7 +206,7 @@ TEST_F(PullNodeTest, ApplyToMissingElement) { setPathToCreate("d"); setPathTaken("a.b.c"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"]["b"]["c"])); + auto result = node.apply(getApplyParams(doc.root()["a"]["b"]["c"]), getUpdateNodeApplyParams()); ASSERT_TRUE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: {b: {c: {}}}}"), doc); @@ -221,7 +223,7 @@ TEST_F(PullNodeTest, ApplyToEmptyArray) { mutablebson::Document doc(fromjson("{a: []}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_TRUE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: []}"), doc); @@ -238,7 +240,7 @@ TEST_F(PullNodeTest, ApplyToArrayMatchingNone) { mutablebson::Document doc(fromjson("{a: [2, 3, 4, 5]}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_TRUE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: [2, 3, 4, 5]}"), doc); @@ -255,7 +257,7 @@ TEST_F(PullNodeTest, ApplyToArrayMatchingOne) { mutablebson::Document doc(fromjson("{a: [0, 1, 2, 3]}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: [1, 2, 3]}"), doc); @@ -272,7 +274,7 @@ TEST_F(PullNodeTest, ApplyToArrayMatchingSeveral) { mutablebson::Document doc(fromjson("{a: [0, 1, 0, 2, 0, 3, 0, 4, 0, 5]}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: [1, 2, 3, 4, 5]}"), doc); @@ -289,7 +291,7 @@ TEST_F(PullNodeTest, ApplyToArrayMatchingAll) { mutablebson::Document doc(fromjson("{a: [0, -1, -2, -3, -4, -5]}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: []}"), doc); @@ -306,7 +308,7 @@ TEST_F(PullNodeTest, ApplyNoIndexDataNoLogBuilder) { mutablebson::Document doc(fromjson("{a: [0, 1, 2, 3]}")); setPathTaken("a"); setLogBuilderToNull(); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: [1, 2, 3]}"), doc); @@ -326,7 +328,7 @@ TEST_F(PullNodeTest, ApplyWithCollation) { mutablebson::Document doc(fromjson("{a: ['zaa', 'zcc', 'zbb', 'zee']}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: ['zaa', 'zbb']}"), doc); @@ -345,7 +347,7 @@ TEST_F(PullNodeTest, ApplyWithCollationDoesNotAffectNonStringMatches) { mutablebson::Document doc(fromjson("{a: [2, 1, 0, -1, -2, -3]}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: [2, 1]}"), doc); @@ -364,7 +366,7 @@ TEST_F(PullNodeTest, ApplyWithCollationDoesNotAffectRegexMatches) { mutablebson::Document doc(fromjson("{a: ['b', 'a', 'aab', 'cb', 'bba']}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: ['b', 'cb']}"), doc); @@ -383,7 +385,7 @@ TEST_F(PullNodeTest, ApplyStringLiteralMatchWithCollation) { mutablebson::Document doc(fromjson("{a: ['b', 'a', 'aab', 'cb', 'bba']}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: []}"), doc); @@ -402,7 +404,7 @@ TEST_F(PullNodeTest, ApplyCollationDoesNotAffectNumberLiteralMatches) { mutablebson::Document doc(fromjson("{a: ['a', 99, 'b', 2, 'c', 99, 'd']}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: ['a', 'b', 2, 'c', 'd']}"), doc); @@ -419,7 +421,7 @@ TEST_F(PullNodeTest, ApplyStringMatchAfterSetCollator) { // First without a collator. mutablebson::Document doc(fromjson("{ a : ['a', 'b', 'c', 'd'] }")); setPathTaken("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: ['a', 'b', 'd']}"), doc); @@ -431,7 +433,7 @@ TEST_F(PullNodeTest, ApplyStringMatchAfterSetCollator) { mutablebson::Document doc2(fromjson("{ a : ['a', 'b', 'c', 'd'] }")); resetApplyParams(); setPathTaken("a"); - result = node.apply(getApplyParams(doc2.root()["a"])); + result = node.apply(getApplyParams(doc2.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: []}"), doc2); @@ -447,7 +449,7 @@ TEST_F(PullNodeTest, ApplyElementMatchAfterSetCollator) { // First without a collator. mutablebson::Document doc(fromjson("{ a : ['a', 'b', 'c', 'd'] }")); setPathTaken("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: ['a', 'b']}"), doc); @@ -459,7 +461,7 @@ TEST_F(PullNodeTest, ApplyElementMatchAfterSetCollator) { mutablebson::Document doc2(fromjson("{ a : ['a', 'b', 'c', 'd'] }")); resetApplyParams(); setPathTaken("a"); - result = node.apply(getApplyParams(doc2.root()["a"])); + result = node.apply(getApplyParams(doc2.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: []}"), doc2); @@ -475,7 +477,7 @@ TEST_F(PullNodeTest, ApplyObjectMatchAfterSetCollator) { // First without a collator. mutablebson::Document doc(fromjson("{a : [{b: 'w'}, {b: 'x'}, {b: 'y'}, {b: 'z'}]}")); setPathTaken("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a : [{b: 'w'}, {b: 'x'}, {b: 'z'}]}"), doc); @@ -487,7 +489,7 @@ TEST_F(PullNodeTest, ApplyObjectMatchAfterSetCollator) { mutablebson::Document doc2(fromjson("{a : [{b: 'w'}, {b: 'x'}, {b: 'y'}, {b: 'z'}]}")); resetApplyParams(); setPathTaken("a"); - result = node.apply(getApplyParams(doc2.root()["a"])); + result = node.apply(getApplyParams(doc2.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: []}"), doc2); @@ -508,7 +510,7 @@ TEST_F(PullNodeTest, SetCollatorDoesNotAffectClone) { // The original node should now have collation. mutablebson::Document doc(fromjson("{ a : ['a', 'b', 'c', 'd'] }")); setPathTaken("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: []}"), doc); @@ -518,7 +520,7 @@ TEST_F(PullNodeTest, SetCollatorDoesNotAffectClone) { mutablebson::Document doc2(fromjson("{ a : ['a', 'b', 'c', 'd'] }")); resetApplyParams(); setPathTaken("a"); - result = cloneNode->apply(getApplyParams(doc2.root()["a"])); + result = cloneNode->apply(getApplyParams(doc2.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: ['a', 'b', 'd']}"), doc2); @@ -538,7 +540,7 @@ TEST_F(PullNodeTest, ApplyComplexDocAndMatching1) { mutablebson::Document doc(fromjson("{a: {b: [{x: 1}, {y: 'y'}, {x: 2}, {z: 'z'}]}}")); setPathTaken("a.b"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"]["b"])); + auto result = node.apply(getApplyParams(doc.root()["a"]["b"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: {b: [{x: 1}, {x: 2}]}}"), doc); @@ -555,7 +557,7 @@ TEST_F(PullNodeTest, ApplyComplexDocAndMatching2) { mutablebson::Document doc(fromjson("{a: {b: [{x: 1}, {y: 'y'}, {x: 2}, {z: 'z'}]}}")); setPathTaken("a.b"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"]["b"])); + auto result = node.apply(getApplyParams(doc.root()["a"]["b"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: {b: [{x: 1}, {x: 2}, {z: 'z'}]}}"), doc); @@ -572,7 +574,7 @@ TEST_F(PullNodeTest, ApplyComplexDocAndMatching3) { mutablebson::Document doc(fromjson("{a: {b: [{x: 1}, {y: 'y'}, {x: 2}, {z: 'z'}]}}")); setPathTaken("a.b"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"]["b"])); + auto result = node.apply(getApplyParams(doc.root()["a"]["b"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: {b: [{x: 2}, {z: 'z'}]}}"), doc); @@ -592,7 +594,7 @@ TEST_F(PullNodeTest, ApplyFullPredicateWithCollation) { fromjson("{a: {b: [{x: 'foo', y: 1}, {x: 'bar', y: 2}, {x: 'baz', y: 3}]}}")); setPathTaken("a.b"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"]["b"])); + auto result = node.apply(getApplyParams(doc.root()["a"]["b"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: {b: []}}"), doc); @@ -609,7 +611,7 @@ TEST_F(PullNodeTest, ApplyScalarValueMod) { mutablebson::Document doc(fromjson("{a: [1, 2, 1, 2, 1, 2]}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: [2, 2, 2]}"), doc); @@ -626,7 +628,7 @@ TEST_F(PullNodeTest, ApplyObjectValueMod) { mutablebson::Document doc(fromjson("{a: [{x: 1}, {y: 2}, {x: 1}, {y: 2}]}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: [{x: 1}, {x: 1}]}"), doc); @@ -644,7 +646,7 @@ TEST_F(PullNodeTest, DocumentationExample1) { fromjson("{flags: ['vme', 'de', 'pse', 'tsc', 'msr', 'pae', 'mce']}")); setPathTaken("flags"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["flags"])); + auto result = node.apply(getApplyParams(doc.root()["flags"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{flags: ['vme', 'de', 'pse', 'tsc', 'pae', 'mce']}"), doc); @@ -662,7 +664,7 @@ TEST_F(PullNodeTest, DocumentationExample2a) { mutablebson::Document doc(fromjson("{votes: [3, 5, 6, 7, 7, 8]}")); setPathTaken("votes"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["votes"])); + auto result = node.apply(getApplyParams(doc.root()["votes"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{votes: [3, 5, 6, 8]}"), doc); @@ -679,7 +681,7 @@ TEST_F(PullNodeTest, DocumentationExample2b) { mutablebson::Document doc(fromjson("{votes: [3, 5, 6, 7, 7, 8]}")); setPathTaken("votes"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["votes"])); + auto result = node.apply(getApplyParams(doc.root()["votes"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{votes: [3, 5, 6]}"), doc); @@ -696,7 +698,7 @@ TEST_F(PullNodeTest, ApplyPullWithObjectValueToArrayWithNonObjectValue) { mutablebson::Document doc(fromjson("{a: [{x: 1}, 2]}")); setPathTaken("a"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["a"])); + auto result = node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_TRUE(result.indexesAffected); ASSERT_EQUALS(fromjson("{a: [2]}"), doc); @@ -714,7 +716,7 @@ TEST_F(PullNodeTest, CannotModifyImmutableField) { setPathTaken("_id.a"); addImmutablePath("_id"); ASSERT_THROWS_CODE_AND_WHAT( - node.apply(getApplyParams(doc.root()["_id"]["a"])), + node.apply(getApplyParams(doc.root()["_id"]["a"]), getUpdateNodeApplyParams()), AssertionException, ErrorCodes::ImmutableField, "Performing an update on the path '_id.a' would modify the immutable field '_id'"); @@ -729,7 +731,7 @@ TEST_F(PullNodeTest, SERVER_3988) { mutablebson::Document doc(fromjson("{x: 1, y: [2, 3, 4, 'abc', 'xyz']}")); setPathTaken("y"); addIndexedPath("a"); - auto result = node.apply(getApplyParams(doc.root()["y"])); + auto result = node.apply(getApplyParams(doc.root()["y"]), getUpdateNodeApplyParams()); ASSERT_FALSE(result.noop); ASSERT_FALSE(result.indexesAffected); ASSERT_EQUALS(fromjson("{x: 1, y: [2, 3, 4, 'abc']}"), doc); |