mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-27 15:06:34 +01:00
e1b3348896
GitOrigin-RevId: aab4310967bd809f753529ca3dc235b8eaa69f7f
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
/**
|
|
* Helper functions for document validation.
|
|
*/
|
|
|
|
/**
|
|
* Assert that a command fails with a DocumentValidationFailure, and verify that the
|
|
* 'errInfo' field is propogated as a part of the doc validation failure.
|
|
*/
|
|
export function assertDocumentValidationFailure(res, coll) {
|
|
assert.commandFailedWithCode(res, ErrorCodes.DocumentValidationFailure, tojson(res));
|
|
if (res instanceof BulkWriteResult) {
|
|
const errors = res.getWriteErrors();
|
|
for (const error of errors) {
|
|
assert(error.hasOwnProperty("errInfo"), tojson(error));
|
|
assert.eq(typeof error["errInfo"], "object", tojson(error));
|
|
}
|
|
} else {
|
|
const error = res instanceof WriteResult ? res.getWriteError() : res;
|
|
assert(error.hasOwnProperty("errInfo"), tojson(error));
|
|
assert.eq(typeof error["errInfo"], "object", tojson(error));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Verifies that the logs contain DocumentValidationFailure.
|
|
*/
|
|
export function assertDocumentValidationFailureCheckLogs(db) {
|
|
checkLog.contains(db, '"codeName":"DocumentValidationFailure"');
|
|
}
|
|
|
|
/**
|
|
* Verifies that validation failed.
|
|
*/
|
|
export function assertFailsValidation(res) {
|
|
assert.writeError(res);
|
|
assert.eq(res.getWriteError().code, ErrorCodes.DocumentValidationFailure);
|
|
}
|