0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-27 15:06:34 +01:00
mongodb/jstests/libs/doc_validation_utils.js
kmznam e1b3348896 SERVER-92728 Move doc_validation_options.js to noPassthrough (#25194)
GitOrigin-RevId: aab4310967bd809f753529ca3dc235b8eaa69f7f
2024-07-23 21:13:50 +00:00

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);
}