diff options
author | Eliot Horowitz <eliot@10gen.com> | 2015-07-09 13:02:01 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2015-07-13 22:17:32 -0400 |
commit | 104ec4c947d65ecf982b633d25eb3afafeed94ca (patch) | |
tree | cd96f4ad464fed707f983cd48437d19086568caa /jstests/core/doc_validation_options.js | |
parent | 9412843d62dd9c8b2eb919c79dd8f2b29e058564 (diff) | |
download | mongo-104ec4c947d65ecf982b633d25eb3afafeed94ca.tar.gz |
SERVER-19144 SERVER-19145 add states and levels to doc validation
Diffstat (limited to 'jstests/core/doc_validation_options.js')
-rw-r--r-- | jstests/core/doc_validation_options.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/jstests/core/doc_validation_options.js b/jstests/core/doc_validation_options.js new file mode 100644 index 00000000000..6057aaf0c10 --- /dev/null +++ b/jstests/core/doc_validation_options.js @@ -0,0 +1,62 @@ +(function() { + "use strict"; + + function assertFailsValidation(res) { + var DocumentValidationFailure = 121; + assert.writeError(res); + assert.eq(res.getWriteError().code, DocumentValidationFailure); + } + + var t = db.doc_validation_options; + t.drop(); + + assert.commandWorked(db.createCollection(t.getName(), + {validator: {a : 1}})); + + assertFailsValidation(t.insert({a:2})); + t.insert({a:1}); + assert.eq(1, t.count()); + + // test default to strict + assertFailsValidation(t.update({}, {$set: {a:2}})); + assert.eq(1, t.find({a:1}).itcount()); + + // check we can do a bad update in warn mode + assert.commandWorked(t.runCommand("collMod", + {validationState: "warn"})); + t.update({}, {$set: {a:2}}); + assert.eq(1, t.find({a:2}).itcount()); + + // TODO: check log for message? + + // make sure persisted + var info = db.getCollectionInfos({name: t.getName()})[0]; + assert.eq("warn", info.options.validationState, tojson(info)); + + // check we can go back to enforce strict + assert.commandWorked(t.runCommand("collMod", + {validationState: "enforce", + validationLevel: "strict"})); + assertFailsValidation(t.update({}, {$set: {a:3}})); + assert.eq(1, t.find({a:2}).itcount()); + + // check bad -> bad is ok + assert.commandWorked(t.runCommand("collMod", + {validationLevel: "moderate"})); + t.update({}, {$set: {a:3}}); + assert.eq(1, t.find({a:3}).itcount()); + + // test create + t.drop(); + assert.commandWorked(db.createCollection(t.getName(), + {validator: {a : 1}, + validationState: "warn"})); + + t.insert({a:2}); + t.insert({a:1}); + assert.eq(2, t.count()); + +})(); + + + |