summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorMihai Andrei <mihai.andrei@10gen.com>2020-07-02 19:21:35 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-07-07 13:38:05 +0000
commite87f6f53c58a75229b40fff7b32de202f2dcccc7 (patch)
treeeafb77ccd24ee11879f904c042eec41e4a3ad76e /jstests
parentff4465b905b331fc82edb8194092917ad0c7255f (diff)
downloadmongo-e87f6f53c58a75229b40fff7b32de202f2dcccc7.tar.gz
SERVER-48781 Introduce 'DocumentValidationErrorExtraInfo' and shell support for document validation errors
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/doc_validation.js23
1 files changed, 14 insertions, 9 deletions
diff --git a/jstests/core/doc_validation.js b/jstests/core/doc_validation.js
index 1b74032c7c3..b45531af62d 100644
--- a/jstests/core/doc_validation.js
+++ b/jstests/core/doc_validation.js
@@ -11,21 +11,26 @@
(function() {
"use strict";
-function assertFailsValidation(res) {
- if (res instanceof WriteResult) {
- assert.writeErrorWithCode(res, ErrorCodes.DocumentValidationFailure, tojson(res));
- } else {
- assert.commandFailedWithCode(res, ErrorCodes.DocumentValidationFailure, tojson(res));
- }
-}
+const collName = "doc_validation";
+const coll = db[collName];
const array = [];
for (let i = 0; i < 2048; i++) {
array.push({arbitrary: i});
}
-const collName = "doc_validation";
-const coll = db[collName];
+function assertFailsValidation(res) {
+ // Assert that validation fails with a 'DocumentValidationFailure' error.
+ assert.commandFailedWithCode(res, ErrorCodes.DocumentValidationFailure, tojson(res));
+ // Verify that the 'errInfo' field is propagated as part of the document validation failure
+ // for WriteErrors.
+ // We don't currently support detailed error info for 'OP_INSERT' and 'OP_UPDATE'.
+ if (coll.getMongo().writeMode() === "commands") {
+ const error = res instanceof WriteResult ? res.getWriteError() : res;
+ assert(error.hasOwnProperty("errInfo"), tojson(error));
+ assert.eq(typeof error["errInfo"], "object", tojson(error));
+ }
+}
/**
* Runs a series of document validation tests using the validator 'validator', which should