summaryrefslogtreecommitdiff
path: root/jstests/libs/doc_validation_utils.js
blob: 71ce072e6a029b8dae25a26155f2da23d3ee69d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
 * 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));
    }
}