summaryrefslogtreecommitdiff
path: root/jstests/libs/doc_validation_utils.js
blob: 6d3e489cbffb0513fab95345fc315a32e32e7d53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
 * 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.
 */
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.
 */
function assertDocumentValidationFailureCheckLogs(db) {
    checkLog.contains(db, '"codeName":"DocumentValidationFailure"');
}