summaryrefslogtreecommitdiff
path: root/jstests/sharding/invalid_system_views_sharded_collection.js
diff options
context:
space:
mode:
authorclang-format-7.0.1 <adam.martin@10gen.com>2019-07-26 18:42:24 -0400
committerADAM David Alan Martin <adam.martin@10gen.com>2019-07-26 18:42:24 -0400
commitc1a45ebbb0530e3d0201321d725527f1eb83ffce (patch)
treef523079dc5ded3052eefbdcaae424b7502df5b25 /jstests/sharding/invalid_system_views_sharded_collection.js
parentc9599d8610c3da0b7c3da65667aff821063cf5b9 (diff)
downloadmongo-c1a45ebbb0530e3d0201321d725527f1eb83ffce.tar.gz
Apply formatting per `clang-format-7.0.1`
Diffstat (limited to 'jstests/sharding/invalid_system_views_sharded_collection.js')
-rw-r--r--jstests/sharding/invalid_system_views_sharded_collection.js214
1 files changed, 101 insertions, 113 deletions
diff --git a/jstests/sharding/invalid_system_views_sharded_collection.js b/jstests/sharding/invalid_system_views_sharded_collection.js
index 1248a7aee3a..899d4482987 100644
--- a/jstests/sharding/invalid_system_views_sharded_collection.js
+++ b/jstests/sharding/invalid_system_views_sharded_collection.js
@@ -4,76 +4,72 @@
*/
(function() {
- "use strict";
-
- function runTest(st, badViewDefinition) {
- const mongos = st.s;
- const config = mongos.getDB("config");
- const db = mongos.getDB("invalid_system_views");
- assert.commandWorked(db.dropDatabase());
-
- assert.commandWorked(config.adminCommand({enableSharding: db.getName()}));
- st.ensurePrimaryShard(db.getName(), st.shard0.shardName);
-
- // Create sharded and unsharded collections, then insert an invalid view into system.views.
- const viewsCollection = db.getCollection("coll");
- const staticCollection = db.getCollection("staticCollection");
- assert.commandWorked(
- config.adminCommand({shardCollection: viewsCollection.getFullName(), key: {a: 1}}));
- assert.commandWorked(
- config.adminCommand({shardCollection: staticCollection.getFullName(), key: {a: 1}}));
-
- assert.commandWorked(viewsCollection.createIndex({x: 1}));
-
- const unshardedColl = db.getCollection("unshardedColl");
- assert.writeOK(unshardedColl.insert({b: "boo"}));
-
- assert.writeOK(db.system.views.insert(badViewDefinition),
- "failed to insert " + tojson(badViewDefinition));
-
- // Test that a command involving views properly fails with a views-specific error code.
- assert.commandFailedWithCode(
- db.runCommand({listCollections: 1}),
- ErrorCodes.InvalidViewDefinition,
- "listCollections should have failed in the presence of an invalid view");
-
- // Helper function to create a message to use if an assertion fails.
- function makeErrorMessage(msg) {
- return msg +
- " should work on a valid, existing collection, despite the presence of bad views" +
- " in system.views";
- }
+"use strict";
+
+function runTest(st, badViewDefinition) {
+ const mongos = st.s;
+ const config = mongos.getDB("config");
+ const db = mongos.getDB("invalid_system_views");
+ assert.commandWorked(db.dropDatabase());
+
+ assert.commandWorked(config.adminCommand({enableSharding: db.getName()}));
+ st.ensurePrimaryShard(db.getName(), st.shard0.shardName);
+
+ // Create sharded and unsharded collections, then insert an invalid view into system.views.
+ const viewsCollection = db.getCollection("coll");
+ const staticCollection = db.getCollection("staticCollection");
+ assert.commandWorked(
+ config.adminCommand({shardCollection: viewsCollection.getFullName(), key: {a: 1}}));
+ assert.commandWorked(
+ config.adminCommand({shardCollection: staticCollection.getFullName(), key: {a: 1}}));
+
+ assert.commandWorked(viewsCollection.createIndex({x: 1}));
+
+ const unshardedColl = db.getCollection("unshardedColl");
+ assert.writeOK(unshardedColl.insert({b: "boo"}));
+
+ assert.writeOK(db.system.views.insert(badViewDefinition),
+ "failed to insert " + tojson(badViewDefinition));
+
+ // Test that a command involving views properly fails with a views-specific error code.
+ assert.commandFailedWithCode(
+ db.runCommand({listCollections: 1}),
+ ErrorCodes.InvalidViewDefinition,
+ "listCollections should have failed in the presence of an invalid view");
+
+ // Helper function to create a message to use if an assertion fails.
+ function makeErrorMessage(msg) {
+ return msg +
+ " should work on a valid, existing collection, despite the presence of bad views" +
+ " in system.views";
+ }
- assert.writeOK(viewsCollection.insert({y: "baz", a: 5}), makeErrorMessage("insert"));
+ assert.writeOK(viewsCollection.insert({y: "baz", a: 5}), makeErrorMessage("insert"));
- assert.writeOK(viewsCollection.update({y: "baz"}, {$set: {y: "qux"}}),
- makeErrorMessage("update"));
+ assert.writeOK(viewsCollection.update({y: "baz"}, {$set: {y: "qux"}}),
+ makeErrorMessage("update"));
- assert.writeOK(viewsCollection.remove({y: "baz"}), makeErrorMessage("remove"));
+ assert.writeOK(viewsCollection.remove({y: "baz"}), makeErrorMessage("remove"));
- assert.commandWorked(
- db.runCommand(
- {findAndModify: viewsCollection.getName(), query: {x: 1, a: 1}, update: {x: 2}}),
- makeErrorMessage("findAndModify with update"));
+ assert.commandWorked(
+ db.runCommand(
+ {findAndModify: viewsCollection.getName(), query: {x: 1, a: 1}, update: {x: 2}}),
+ makeErrorMessage("findAndModify with update"));
- assert.commandWorked(
- db.runCommand(
- {findAndModify: viewsCollection.getName(), query: {x: 2, a: 1}, remove: true}),
- makeErrorMessage("findAndModify with remove"));
+ assert.commandWorked(
+ db.runCommand(
+ {findAndModify: viewsCollection.getName(), query: {x: 2, a: 1}, remove: true}),
+ makeErrorMessage("findAndModify with remove"));
- const lookup = {
- $lookup: {
- from: unshardedColl.getName(),
- localField: "_id",
- foreignField: "_id",
- as: "match"
- }
- };
- assert.commandWorked(
- db.runCommand({aggregate: viewsCollection.getName(), pipeline: [lookup], cursor: {}}),
- makeErrorMessage("aggregate with $lookup"));
+ const lookup = {
+ $lookup:
+ {from: unshardedColl.getName(), localField: "_id", foreignField: "_id", as: "match"}
+ };
+ assert.commandWorked(
+ db.runCommand({aggregate: viewsCollection.getName(), pipeline: [lookup], cursor: {}}),
+ makeErrorMessage("aggregate with $lookup"));
- const graphLookup = {
+ const graphLookup = {
$graphLookup: {
from: unshardedColl.getName(),
startWith: "$_id",
@@ -82,54 +78,46 @@
as: "match"
}
};
- assert.commandWorked(
- db.runCommand(
- {aggregate: viewsCollection.getName(), pipeline: [graphLookup], cursor: {}}),
- makeErrorMessage("aggregate with $graphLookup"));
-
- assert.commandWorked(db.runCommand({dropIndexes: viewsCollection.getName(), index: "x_1"}),
- makeErrorMessage("dropIndexes"));
-
- assert.commandWorked(viewsCollection.createIndex({x: 1}),
- makeErrorMessage("createIndexes"));
-
- assert.commandWorked(
- db.runCommand({collMod: viewsCollection.getName(), validator: {x: {$type: "string"}}}),
- makeErrorMessage("collMod"));
-
- assert.commandWorked(db.runCommand({drop: viewsCollection.getName()}),
- makeErrorMessage("drop"));
- assert.commandWorked(db.runCommand({drop: staticCollection.getName()}),
- makeErrorMessage("drop"));
- assert.commandWorked(db.runCommand({drop: unshardedColl.getName()}),
- makeErrorMessage("drop"));
-
- // Drop the offending view so that the validate hook succeeds.
- db.system.views.remove(badViewDefinition);
- }
-
- const st = new ShardingTest({name: "views_sharded", shards: 2, other: {enableBalancer: false}});
-
- runTest(st,
- {_id: "invalid_system_views.badViewStringPipeline", viewOn: "coll", pipeline: "bad"});
- runTest(st,
- {_id: "invalid_system_views.badViewEmptyObjectPipeline", viewOn: "coll", pipeline: {}});
- runTest(st,
- {_id: "invalid_system_views.badViewNumericalPipeline", viewOn: "coll", pipeline: 7});
- runTest(st, {
- _id: "invalid_system_views.badViewArrayWithIntegerPipeline",
- viewOn: "coll",
- pipeline: [1]
- });
- runTest(st, {
- _id: "invalid_system_views.badViewArrayWithEmptyArrayPipeline",
- viewOn: "coll",
- pipeline: [[]]
- });
- runTest(st, {_id: 7, viewOn: "coll", pipeline: []});
- runTest(st, {_id: "invalid_system_views.embedded\0null", viewOn: "coll", pipeline: []});
- runTest(st, {_id: "invalidNotFullyQualifiedNs", viewOn: "coll", pipeline: []});
- runTest(st, {_id: "invalid_system_views.missingViewOnField", pipeline: []});
-
- st.stop();
+ assert.commandWorked(
+ db.runCommand({aggregate: viewsCollection.getName(), pipeline: [graphLookup], cursor: {}}),
+ makeErrorMessage("aggregate with $graphLookup"));
+
+ assert.commandWorked(db.runCommand({dropIndexes: viewsCollection.getName(), index: "x_1"}),
+ makeErrorMessage("dropIndexes"));
+
+ assert.commandWorked(viewsCollection.createIndex({x: 1}), makeErrorMessage("createIndexes"));
+
+ assert.commandWorked(
+ db.runCommand({collMod: viewsCollection.getName(), validator: {x: {$type: "string"}}}),
+ makeErrorMessage("collMod"));
+
+ assert.commandWorked(db.runCommand({drop: viewsCollection.getName()}),
+ makeErrorMessage("drop"));
+ assert.commandWorked(db.runCommand({drop: staticCollection.getName()}),
+ makeErrorMessage("drop"));
+ assert.commandWorked(db.runCommand({drop: unshardedColl.getName()}), makeErrorMessage("drop"));
+
+ // Drop the offending view so that the validate hook succeeds.
+ db.system.views.remove(badViewDefinition);
+}
+
+const st = new ShardingTest({name: "views_sharded", shards: 2, other: {enableBalancer: false}});
+
+runTest(st, {_id: "invalid_system_views.badViewStringPipeline", viewOn: "coll", pipeline: "bad"});
+runTest(st, {_id: "invalid_system_views.badViewEmptyObjectPipeline", viewOn: "coll", pipeline: {}});
+runTest(st, {_id: "invalid_system_views.badViewNumericalPipeline", viewOn: "coll", pipeline: 7});
+runTest(
+ st,
+ {_id: "invalid_system_views.badViewArrayWithIntegerPipeline", viewOn: "coll", pipeline: [1]});
+runTest(st, {
+ _id: "invalid_system_views.badViewArrayWithEmptyArrayPipeline",
+ viewOn: "coll",
+ pipeline: [[]]
+});
+runTest(st, {_id: 7, viewOn: "coll", pipeline: []});
+runTest(st, {_id: "invalid_system_views.embedded\0null", viewOn: "coll", pipeline: []});
+runTest(st, {_id: "invalidNotFullyQualifiedNs", viewOn: "coll", pipeline: []});
+runTest(st, {_id: "invalid_system_views.missingViewOnField", pipeline: []});
+
+st.stop();
}());