diff options
Diffstat (limited to 'src/mongo/db/pipeline/document_source_merge_test.cpp')
| -rw-r--r-- | src/mongo/db/pipeline/document_source_merge_test.cpp | 107 |
1 files changed, 12 insertions, 95 deletions
diff --git a/src/mongo/db/pipeline/document_source_merge_test.cpp b/src/mongo/db/pipeline/document_source_merge_test.cpp index 1987d09da07..e7d87707900 100644 --- a/src/mongo/db/pipeline/document_source_merge_test.cpp +++ b/src/mongo/db/pipeline/document_source_merge_test.cpp @@ -29,10 +29,8 @@ #include "mongo/platform/basic.h" -#include "mongo/unittest/bson_test_util.h" #include <boost/intrusive_ptr.hpp> -#include "mongo/bson/unordered_fields_bsonobj_comparator.h" #include "mongo/db/exec/document_value/document.h" #include "mongo/db/exec/document_value/document_value_test_util.h" #include "mongo/db/pipeline/aggregation_context_fixture.h" @@ -794,12 +792,12 @@ TEST_F(DocumentSourceMergeTest, SerializeDefaultLetVariable) { // Test the behaviour of 'let' serialization for each whenNotMatched mode. TEST_F(DocumentSourceMergeTest, SerializeLetVariables) { - auto pipeline = BSON_ARRAY(BSON("$project" << BSON("_id" << true << "x" - << "$$v1" - << "y" - << "$$v2" - << "z" - << "$$v3"))); + auto pipeline = BSON_ARRAY(BSON("$project" << BSON("x" + << "$$v1" + << "y" + << "$$v2" + << "z" + << "$$v3"))); const auto createAndSerializeMergeStage = [this, &pipeline](StringData whenNotMatched) { auto spec = BSON("$merge" << BSON("into" @@ -845,8 +843,8 @@ TEST_F(DocumentSourceMergeTest, SerializeLetVariables) { TEST_F(DocumentSourceMergeTest, SerializeLetArrayVariable) { for (auto&& whenNotMatched : {"insert", "fail", "discard"}) { - auto pipeline = BSON_ARRAY(BSON("$project" << BSON("_id" << true << "x" - << "$$v1"))); + auto pipeline = BSON_ARRAY(BSON("$project" << BSON("x" + << "$$v1"))); auto spec = BSON( "$merge" << BSON("into" << "target_collection" @@ -874,9 +872,8 @@ TEST_F(DocumentSourceMergeTest, SerializeLetArrayVariable) { // SERVER-41272, this test should be updated to accordingly. TEST_F(DocumentSourceMergeTest, SerializeNullLetVariablesAsDefault) { for (auto&& whenNotMatched : {"insert", "fail", "discard"}) { - auto pipeline = BSON_ARRAY(BSON("$project" << BSON("_id" << true << "x" - << BSON("$const" - << "1")))); + auto pipeline = BSON_ARRAY(BSON("$project" << BSON("x" + << "1"))); auto spec = BSON("$merge" << BSON("into" << "target_collection" << "let" << BSONNULL << "whenMatched" << pipeline @@ -893,9 +890,8 @@ TEST_F(DocumentSourceMergeTest, SerializeNullLetVariablesAsDefault) { TEST_F(DocumentSourceMergeTest, SerializeEmptyLetVariables) { for (auto&& whenNotMatched : {"insert", "fail", "discard"}) { - auto pipeline = BSON_ARRAY(BSON("$project" << BSON("_id" << true << "x" - << BSON("$const" - << "1")))); + auto pipeline = BSON_ARRAY(BSON("$project" << BSON("x" + << "1"))); auto spec = BSON("$merge" << BSON("into" << "target_collection" << "let" << BSONObj() << "whenMatched" << pipeline @@ -911,41 +907,6 @@ TEST_F(DocumentSourceMergeTest, SerializeEmptyLetVariables) { } } -TEST_F(DocumentSourceMergeTest, SerializeEmptyLetVariableMentionNew) { - auto pipeline = BSON_ARRAY(fromjson("{$project: {_id: true, x: '$$new'}}")); - auto spec = - BSON("$merge" << BSON("into" - << "target_collection" - << "let" << BSONObj() << "whenMatched" << pipeline << "whenNotMatched" - << "insert")); - auto mergeStage = createMergeStage(spec); - ASSERT(mergeStage); - auto serialized = mergeStage->serialize().getDocument(); - ASSERT_BSONOBJ_EQ_AUTO( // NOLINT - R"({ - "$merge": { - "into": { - "db": "unittests", - "coll": "target_collection" - }, - "on": "_id", - "let": { - "new": "$$ROOT" - }, - "whenMatched": [ - { - "$project": { - "_id": true, - "x": "$$new" - } - } - ], - "whenNotMatched": "insert" - } - })", - serialized.toBson()); -} - TEST_F(DocumentSourceMergeTest, OnlyObjectCanBeUsedAsLetVariables) { for (auto&& whenNotMatched : {"insert", "fail", "discard"}) { auto pipeline = BSON_ARRAY(BSON("$project" << BSON("x" @@ -989,49 +950,5 @@ TEST_F(DocumentSourceMergeTest, FailsToParseIfOnFieldHaveDuplicates) { ASSERT_THROWS_CODE(createMergeStage(spec), AssertionException, 31465); } -TEST_F(DocumentSourceMergeTest, QueryShape) { - auto pipeline = BSON_ARRAY(BSON("$project" << BSON("x" - << "1"))); - auto let = BSON("new" - << "$$ROOT" - << "year" - << "2020"); - auto spec = - BSON("$merge" << BSON("into" - << "target_collection" - << "let" << let << "whenMatched" << pipeline << "whenNotMatched" - << "insert")); - auto mergeStage = createMergeStage(spec); - ASSERT(mergeStage); - auto serialized = mergeStage->serialize().getDocument(); - - auto expectedBson = fromjson(R"({ - "$merge": { - "into": { - "db": "HASH<unittests>", - "coll": "HASH<target_collection>" - }, - "on": "HASH<_id>", - "let": { - "HASH<year>": "?string", - "HASH<new>": "$$ROOT" - }, - "whenMatched": [ - { - "$project": { - "HASH<_id>": true, - "HASH<x>": "?string" - } - } - ], - "whenNotMatched": "insert" - } - })"); - auto result = redact(*mergeStage); - UnorderedFieldsBSONObjComparator comparator; - ASSERT_EQ(0, comparator.compare(redact(*mergeStage), expectedBson)) - << "Expected [" << expectedBson << "] but found [" << result << "]"; -} - } // namespace } // namespace mongo |
