summaryrefslogtreecommitdiff
path: root/jstests/readonly
diff options
context:
space:
mode:
authorAdam Midvidy <amidvidy@gmail.com>2016-03-16 13:35:41 -0400
committerAdam Midvidy <amidvidy@gmail.com>2016-03-17 13:07:29 -0400
commitf34d7bed806c10dd680695b03035b64f57245a06 (patch)
tree2e8e73e99dd775470bbdca03620eb4e78150b7f0 /jstests/readonly
parent08f686baf91c9bf201d5a98ab7a1d93c1697a690 (diff)
downloadmongo-f34d7bed806c10dd680695b03035b64f57245a06.tar.gz
SERVER-22355 add negative tests of write operations to read_only suite
Diffstat (limited to 'jstests/readonly')
-rw-r--r--jstests/readonly/catalog_ops.js71
-rw-r--r--jstests/readonly/write_ops.js (renamed from jstests/readonly/insert.js)9
2 files changed, 79 insertions, 1 deletions
diff --git a/jstests/readonly/catalog_ops.js b/jstests/readonly/catalog_ops.js
new file mode 100644
index 00000000000..e41293b1d96
--- /dev/null
+++ b/jstests/readonly/catalog_ops.js
@@ -0,0 +1,71 @@
+load("jstests/readonly/lib/read_only_test.js");
+
+runReadOnlyTest(function() {
+ 'use strict';
+ return {
+ name: 'catalog_ops',
+
+ collectionNames: ["foo", "bar", "baz", "garply"],
+ indexSpecs: [{a: 1}, {a: 1, b: -1}, {a: 1, b: 1, c: -1}],
+
+ load: function(writableCollection) {
+
+ // Catalog guarantees are neccessarily weaker in sharded systems since mongos is not
+ // read-only aware.
+ if (TestData.fixture === "sharded") return;
+
+ var db = writableCollection.getDB();
+
+ // Create some collections so we can verify that listCollections works in read-only
+ // mode.
+ for (var collectionName of this.collectionNames) {
+ assert.commandWorked(db.runCommand({create: collectionName}));
+ }
+
+ // Create some indexes so we can verify that listIndexes works in read-only mode.
+ for (var indexSpec of this.indexSpecs) {
+ assert.commandWorked(writableCollection.createIndex(indexSpec));
+ }
+ },
+ exec: function(readableCollection) {
+
+ // Catalog guarantees are neccessarily weaker in sharded systems since mongos is not
+ // read-only aware.
+ if (TestData.fixture === "sharded") return;
+
+ // Check that we can read our collections out.
+ var db = readableCollection.getDB();
+ var collections = db.getCollectionNames(); // runs listCollections internally.
+ for (var collectionName of this.collectionNames) {
+ assert.contains(collectionName, collections,
+ "expected to have a collection '" + collectionName +
+ "' in the output of listCollections, which was " +
+ tojson(collections));
+ }
+ assert.gte(collections.length, this.collectionNames.length);
+
+ // Check that create fails.
+ assert.commandFailed(db.runCommand({create: "quux"}));
+
+ // Check that drop fails.
+ assert.commandFailed(db.runCommand({drop: "foo"}));
+
+ // Check that dropDatabase fails.
+ assert.commandFailed(db.runCommand({dropDatabase: 1}));
+
+ // Check that we can read our indexes out.
+ var indexes = readableCollection.getIndexes();
+ var actualIndexes = indexes.map((fullSpec) => { return fullSpec.key; });
+ var expectedIndexes = Array.concat([{_id: 1}], this.indexSpecs);
+
+ assert.docEq(actualIndexes, expectedIndexes);
+
+ // Check that createIndexes fails.
+ assert.commandFailed(db.runCommand({createIndexes: this.name,
+ indexes: [
+ {key: {d : 1},
+ name: "foo"}
+ ]}));
+ }
+ };
+}());
diff --git a/jstests/readonly/insert.js b/jstests/readonly/write_ops.js
index 503399fd20c..bde5d231ca6 100644
--- a/jstests/readonly/insert.js
+++ b/jstests/readonly/write_ops.js
@@ -3,12 +3,19 @@ load("jstests/readonly/lib/read_only_test.js");
runReadOnlyTest(function() {
'use strict';
return {
- name: 'insert',
+ name: 'write_ops',
load: function(writableCollection) {
assert.writeOK(writableCollection.insert({x: 1}));
},
exec: function(readableCollection) {
+ // Test that insert fails.
assert.writeError(readableCollection.insert({x: 2}));
+
+ // Test that delete fails.
+ assert.writeError(readableCollection.remove({x: 1}));
+
+ // Test that update fails.
+ assert.writeError(readableCollection.update({x: 1}, {$inc: {x: 1}}));
}
};
}());