summaryrefslogtreecommitdiff
path: root/src/mongo/db/update/update_object_node_test.cpp
diff options
context:
space:
mode:
authorJustin Seyster <justin.seyster@mongodb.com>2017-06-02 11:30:52 -0400
committerJustin Seyster <justin.seyster@mongodb.com>2017-06-02 11:30:52 -0400
commit1036e4ad6cf2465612faaa7cc57693f2c80e41af (patch)
tree78a75f11832990f2e81baf75579a55a67e8db53b /src/mongo/db/update/update_object_node_test.cpp
parent19a48549ee1eba1a00fd3477839859fbc0f27e22 (diff)
downloadmongo-1036e4ad6cf2465612faaa7cc57693f2c80e41af.tar.gz
SERVER-28767 Create IncNode/MulNode
A lot of the update modifiers have behavior that is very similar to $set in how paths that don't yet exist get created (including $inc and $mul, which are added in this commit). The new PathCreatingNode will allow us to use the same path creation code path in all those modifiers.
Diffstat (limited to 'src/mongo/db/update/update_object_node_test.cpp')
-rw-r--r--src/mongo/db/update/update_object_node_test.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/mongo/db/update/update_object_node_test.cpp b/src/mongo/db/update/update_object_node_test.cpp
index be71ef001fe..a2fc156bb71 100644
--- a/src/mongo/db/update/update_object_node_test.cpp
+++ b/src/mongo/db/update/update_object_node_test.cpp
@@ -53,6 +53,22 @@ TEST(UpdateObjectNodeTest, InvalidPathFailsToParse) {
ASSERT_EQ(result.getStatus().reason(), "An empty update path is not valid.");
}
+TEST(UpdateObjectNodeTest, ValidIncPathParsesSuccessfully) {
+ auto update = fromjson("{$inc: {'a.b': 5}}");
+ const CollatorInterface* collator = nullptr;
+ UpdateObjectNode root;
+ ASSERT_OK(UpdateObjectNode::parseAndMerge(
+ &root, modifiertable::ModifierType::MOD_INC, update["$inc"]["a.b"], collator));
+}
+
+TEST(UpdateObjectNodeTest, ValidMulPathParsesSuccessfully) {
+ auto update = fromjson("{$mul: {'a.b': 5}}");
+ const CollatorInterface* collator = nullptr;
+ UpdateObjectNode root;
+ ASSERT_OK(UpdateObjectNode::parseAndMerge(
+ &root, modifiertable::ModifierType::MOD_MUL, update["$mul"]["a.b"], collator));
+}
+
TEST(UpdateObjectNodeTest, ValidSetPathParsesSuccessfully) {
auto update = fromjson("{$set: {'a.b': 5}}");
const CollatorInterface* collator = nullptr;
@@ -114,15 +130,15 @@ TEST(UpdateObjectNodeTest, PositionalElementFirstPositionFailsToParse) {
}
// TODO SERVER-28777: All modifier types should succeed.
-TEST(UpdateObjectNodeTest, IncFailsToParse) {
- auto update = fromjson("{$inc: {a: 5}}");
+TEST(UpdateObjectNodeTest, PushFailsToParse) {
+ auto update = fromjson("{$push: {a: 5}}");
const CollatorInterface* collator = nullptr;
UpdateObjectNode root;
auto result = UpdateObjectNode::parseAndMerge(
- &root, modifiertable::ModifierType::MOD_INC, update["$inc"]["a"], collator);
+ &root, modifiertable::ModifierType::MOD_PUSH, update["$push"]["a"], collator);
ASSERT_NOT_OK(result);
ASSERT_EQ(result.getStatus().code(), ErrorCodes::FailedToParse);
- ASSERT_EQ(result.getStatus().reason(), "Cannot construct modifier of type 3");
+ ASSERT_EQ(result.getStatus().reason(), "Cannot construct modifier of type 10");
}
TEST(UpdateObjectNodeTest, TwoModifiersOnSameFieldFailToParse) {