jstests/fle2/libs/encrypted_client_util.js
/**
     * Take a snapshot of a collection sorted by _id, run a operation, take a second snapshot.
     *
     * Ensure that the documents listed by index in unchangedDocumentIndexArray remain unchanged.
     * Ensure that the documents listed by index in changedDocumentIndexArray are changed.
     *
     * @param {string} collName
     * @param {Array} unchangedDocumentIndexArray
     * @param {Array} changedDocumentIndexArray
     * @param {Function} func
     * @returns
     */
Take a snapshot of a collection sorted by _id, run a operation, take a second snapshot.
Ensure that the documents listed by index in unchangedDocumentIndexArray remain unchanged.
Ensure that the documents listed by index in changedDocumentIndexArray are changed.


Take a snapshot of a collection sorted by _id run a operation take a second snapshot . Ensure that the documents listed by index in unchangedDocumentIndexArray remain unchanged . Ensure that the documents listed by index in changedDocumentIndexArray are changed .
assertDocumentChanges(collName, unchangedDocumentIndexArray, changedDocumentIndexArray, func) {
        let coll = this._edb.getCollection(collName);
        let beforeDocuments = coll.find({}).sort({_id: 1}).toArray();
        let x = func();
        let afterDocuments = coll.find({}).sort({_id: 1}).toArray();
        for (let unchangedDocumentIndex of unchangedDocumentIndexArray) {
            assert.eq(beforeDocuments[unchangedDocumentIndex],
                      afterDocuments[unchangedDocumentIndex],
                      "Expected document index '" + unchangedDocumentIndex + "' to be the same." +
                          tojson(beforeDocuments[unchangedDocumentIndex]) + "\n==========\n" +
                          tojson(afterDocuments[unchangedDocumentIndex]));
        }
        for (let changedDocumentIndex of changedDocumentIndexArray) {
            assert.neq(
                beforeDocuments[changedDocumentIndex],
                afterDocuments[changedDocumentIndex],
                "Expected document index '" + changedDocumentIndex +
                    "' to be different. == " + tojson(beforeDocuments[changedDocumentIndex]) +
                    "\n==========\n" + tojson(afterDocuments[changedDocumentIndex]));
        }
        return x;
    }
assertDocumentChanges ( collName , unchangedDocumentIndexArray , changedDocumentIndexArray , func ) { let coll = this . _edb . getCollection ( collName ) ; let beforeDocuments = coll . find ( { } ) . sort ( { _id : 1 } ) . toArray ( ) ; let x = func ( ) ; let afterDocuments = coll . find ( { } ) . sort ( { _id : 1 } ) . toArray ( ) ; for ( let unchangedDocumentIndex of unchangedDocumentIndexArray ) { assert . eq ( beforeDocuments [ unchangedDocumentIndex ] , afterDocuments [ unchangedDocumentIndex ] , "Expected document index '" + unchangedDocumentIndex + "' to be the same." + tojson ( beforeDocuments [ unchangedDocumentIndex ] ) + "\n==========\n" + tojson ( afterDocuments [ unchangedDocumentIndex ] ) ) ; } for ( let changedDocumentIndex of changedDocumentIndexArray ) { assert . neq ( beforeDocuments [ changedDocumentIndex ] , afterDocuments [ changedDocumentIndex ] , "Expected document index '" + changedDocumentIndex + "' to be different. == " + tojson ( beforeDocuments [ changedDocumentIndex ] ) + "\n==========\n" + tojson ( afterDocuments [ changedDocumentIndex ] ) ) ; } return x ; }
Take a snapshot of a collection sorted by _id, run a operation, take a second snapshot.
Take a snapshot of a collection sorted by _id run a operation take a second snapshot .