diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2017-04-21 16:13:21 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2017-05-01 10:00:22 -0400 |
commit | 314809d7cdda82d6c2741dbe2daf119270e5ad02 (patch) | |
tree | 6fe3ede8bac16e227d1046611e4bcb827fd99e39 /src/mongo/db/update/path_support_test.cpp | |
parent | 5273c2bad7df58c44afdd677609b8656f399a906 (diff) | |
download | mongo-314809d7cdda82d6c2741dbe2daf119270e5ad02.tar.gz |
SERVER-28759 Implement SetNode::apply()
Diffstat (limited to 'src/mongo/db/update/path_support_test.cpp')
-rw-r--r-- | src/mongo/db/update/path_support_test.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mongo/db/update/path_support_test.cpp b/src/mongo/db/update/path_support_test.cpp index 5091a2b8cba..5ea820bbf7b 100644 --- a/src/mongo/db/update/path_support_test.cpp +++ b/src/mongo/db/update/path_support_test.cpp @@ -198,6 +198,18 @@ TEST_F(SimpleDoc, NotCommonPrefix) { ASSERT_EQUALS(root().rightChild().leftSibling().getFieldName(), "a"); } +TEST_F(SimpleDoc, CreatePathAtFailsIfElemFoundIsNonObjectNonArray) { + setField("b"); + + auto elemFound = root()["a"]; + auto newElem = doc().makeElementInt("b", 1); + ASSERT_TRUE(newElem.ok()); + auto result = createPathAt(field(), 0, elemFound, newElem); + ASSERT_NOT_OK(result); + ASSERT_EQ(result.code(), ErrorCodes::PathNotViable); + ASSERT_EQ(result.reason(), "Cannot create field 'b' in element {a: 1}"); +} + class NestedDoc : public mongo::unittest::Test { public: NestedDoc() : _doc() {} @@ -520,6 +532,18 @@ TEST_F(ArrayDoc, NonNumericPathInArray) { ASSERT_EQUALS(elemFound.compareWithElement(root()["b"], nullptr), 0); } +TEST_F(ArrayDoc, CreatePathAtFailsIfElemFoundIsArrayAndIdxFoundFieldIsNonNumeric) { + setField("b"); + + auto elemFound = root()["a"]; + auto newElem = doc().makeElementInt("b", 1); + ASSERT_TRUE(newElem.ok()); + auto result = createPathAt(field(), 0, elemFound, newElem); + ASSERT_NOT_OK(result); + ASSERT_EQ(result.code(), ErrorCodes::PathNotViable); + ASSERT_EQ(result.reason(), "Cannot create field 'b' in element {a: []}"); +} + // // Tests of equality extraction from MatchExpressions // NONGOAL: Testing query/match expression parsing and optimization |