diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2017-04-14 16:06:18 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2017-04-20 13:22:12 -0400 |
commit | 0293c14cbdc5646d9f09f4fe5b2a27e6d540dce0 (patch) | |
tree | 427f823c34f54fcd8d7fa28969ce7f40c740a354 /src/mongo/db/update/set_node_test.cpp | |
parent | c08590a6ac9dc54c9d910822d47ea17140b56f89 (diff) | |
download | mongo-0293c14cbdc5646d9f09f4fe5b2a27e6d540dce0.tar.gz |
SERVER-28621 Parse BSON update expression into an UpdateNode tree
Diffstat (limited to 'src/mongo/db/update/set_node_test.cpp')
-rw-r--r-- | src/mongo/db/update/set_node_test.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/mongo/db/update/set_node_test.cpp b/src/mongo/db/update/set_node_test.cpp new file mode 100644 index 00000000000..c600af34158 --- /dev/null +++ b/src/mongo/db/update/set_node_test.cpp @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2017 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects + * for all of the code used other than as permitted herein. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you do not + * wish to do so, delete this exception statement from your version. If you + * delete this exception statement from all source files in the program, + * then also delete it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/update/set_node.h" + +#include "mongo/db/json.h" +#include "mongo/unittest/death_test.h" +#include "mongo/unittest/unittest.h" + +namespace { + +using namespace mongo; + +DEATH_TEST(SetNodeTest, InitFailsForEmptyElement, "Invariant failure modExpr.ok()") { + auto update = fromjson("{$set: {}}"); + const CollatorInterface* collator = nullptr; + SetNode node; + node.init(update["$set"].embeddedObject().firstElement(), collator); +} + +TEST(SetNodeTest, InitSucceedsForNonemptyElement) { + auto update = fromjson("{$set: {a: 5}}"); + const CollatorInterface* collator = nullptr; + SetNode node; + ASSERT_OK(node.init(update["$set"]["a"], collator)); +} + +} // namespace |