diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2016-05-03 14:44:51 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2016-05-06 17:08:24 -0400 |
commit | c4e741fdc08f40142c474a5656163439e0039756 (patch) | |
tree | 85c0420cd1383072cdef20e91d22c7eefe728b84 /src/mongo/db/ops/write_ops_parsers_test.cpp | |
parent | c2a3430e8ccb4e9af638ad84e9c4d365d094355a (diff) | |
download | mongo-c4e741fdc08f40142c474a5656163439e0039756.tar.gz |
SERVER-23473 Add collation parameter to update and delete
Diffstat (limited to 'src/mongo/db/ops/write_ops_parsers_test.cpp')
-rw-r--r-- | src/mongo/db/ops/write_ops_parsers_test.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/mongo/db/ops/write_ops_parsers_test.cpp b/src/mongo/db/ops/write_ops_parsers_test.cpp index 1cc41da34e7..252479b4915 100644 --- a/src/mongo/db/ops/write_ops_parsers_test.cpp +++ b/src/mongo/db/ops/write_ops_parsers_test.cpp @@ -84,6 +84,21 @@ TEST(CommandWriteOpsParsers, GarbageFieldsInDeleteDoc) { auto cmd = BSON("delete" << "bar" << "deletes" << BSON_ARRAY("q" << BSONObj() << "limit" << 0 << "GARBAGE" << 1)); +} + +TEST(CommandWriteOpsParsers, BadCollationFieldInUpdateDoc) { + auto cmd = + BSON("update" + << "bar" + << "updates" << BSON_ARRAY("q" << BSONObj() << "u" << BSONObj() << "collation" << 1)); + ASSERT_THROWS_CODE(parseInsertCommand("foo", cmd), UserException, ErrorCodes::FailedToParse); +} + +TEST(CommandWriteOpsParsers, BadCollationFieldInDeleteDoc) { + auto cmd = + BSON("delete" + << "bar" + << "deletes" << BSON_ARRAY("q" << BSONObj() << "limit" << 0 << "collation" << 1)); ASSERT_THROWS_CODE(parseInsertCommand("foo", cmd), UserException, ErrorCodes::FailedToParse); } @@ -123,11 +138,14 @@ TEST(CommandWriteOpsParsers, Update) { const auto ns = NamespaceString("test", "foo"); const BSONObj query = BSON("x" << 1); const BSONObj update = BSON("$inc" << BSON("x" << 1)); + const BSONObj collation = BSON("locale" + << "en_US"); for (bool upsert : {false, true}) { for (bool multi : {false, true}) { auto cmd = BSON("update" << ns.coll() << "updates" - << BSON_ARRAY(BSON("q" << query << "u" << update << "upsert" - << upsert << "multi" << multi))); + << BSON_ARRAY(BSON("q" << query << "u" << update << "collation" + << collation << "upsert" << upsert + << "multi" << multi))); auto op = parseUpdateCommand(ns.db(), cmd); ASSERT_EQ(op.ns.ns(), ns.ns()); ASSERT(!op.bypassDocumentValidation); @@ -135,6 +153,7 @@ TEST(CommandWriteOpsParsers, Update) { ASSERT_EQ(op.updates.size(), 1u); ASSERT_EQ(op.updates[0].query, query); ASSERT_EQ(op.updates[0].update, update); + ASSERT_EQ(op.updates[0].collation, collation); ASSERT_EQ(op.updates[0].upsert, upsert); ASSERT_EQ(op.updates[0].multi, multi); } @@ -144,15 +163,19 @@ TEST(CommandWriteOpsParsers, Update) { TEST(CommandWriteOpsParsers, Remove) { const auto ns = NamespaceString("test", "foo"); const BSONObj query = BSON("x" << 1); + const BSONObj collation = BSON("locale" + << "en_US"); for (bool multi : {false, true}) { auto cmd = BSON("delete" << ns.coll() << "deletes" - << BSON_ARRAY(BSON("q" << query << "limit" << (multi ? 0 : 1)))); + << BSON_ARRAY(BSON("q" << query << "collation" << collation + << "limit" << (multi ? 0 : 1)))); auto op = parseDeleteCommand(ns.db(), cmd); ASSERT_EQ(op.ns.ns(), ns.ns()); ASSERT(!op.bypassDocumentValidation); ASSERT_EQ(op.continueOnError, false); ASSERT_EQ(op.deletes.size(), 1u); ASSERT_EQ(op.deletes[0].query, query); + ASSERT_EQ(op.deletes[0].collation, collation); ASSERT_EQ(op.deletes[0].multi, multi); } } |