MCPcopy
hub / github.com/mongodb/node-mongodb-native / testOperation

Function testOperation

test/tools/spec-runner/index.js:790–953  ·  test/tools/spec-runner/index.js::testOperation

* @param {object} operation the operation definition from the spec test * @param {object} obj the object to call the operation on * @param {object} context a context object containing sessions used for the test * @param {object} [options] Optional settings * @param {boolean} [options.swallowOper

(operation, obj, context, options)

Source from the content-addressed store, hash-verified

788 * @param {boolean} [options.swallowOperationErrors] Generally we want to observe operation errors, validate them against our expectations, and then swallow them. In cases like `withTransaction` we want to use the same `testOperations` to build the lambda, and in those cases it is not desireable to swallow the errors, since we need to test this behavior.
789 */
790function testOperation(operation, obj, context, options) {
791 options = options || { swallowOperationErrors: true };
792 const opOptions = {};
793 let args = [];
794 const operationName = translateOperationName(operation.name);
795
796 let opPromise;
797 if (kOperations.has(operationName)) {
798 opPromise = kOperations.get(operationName)(operation, obj, context, options);
799 } else {
800 if (operation.arguments) {
801 args = resolveOperationArgs(operationName, operation.arguments, context);
802
803 if (args == null) {
804 args = [];
805 Object.keys(operation.arguments).forEach(key => {
806 if (key === class="st">'callback') {
807 args.push(() =>
808 testOperations(operation.arguments.callback, context, {
809 swallowOperationErrors: false
810 })
811 );
812 return;
813 }
814
815 if ([class="st">'filter', class="st">'fieldName', class="st">'document', class="st">'documents', class="st">'pipeline'].indexOf(key) !== -1) {
816 return args.unshift(operation.arguments[key]);
817 }
818
819 if (key === class="st">'command') return args.unshift(operation.arguments[key]);
820 if (key === class="st">'requests')
821 return args.unshift(extractBulkRequests(operation.arguments[key]));
822 if (key === class="st">'update' || key === class="st">'replacement') return args.push(operation.arguments[key]);
823 if (key === class="st">'session') {
824 if (isTransactionCommand(operationName)) return;
825 opOptions.session = context[operation.arguments.session];
826 return;
827 }
828
829 if (key === class="st">'returnDocument') {
830 opOptions.returnDocument = operation.arguments[key].toLowerCase();
831 return;
832 }
833
834 if (key === class="st">'options') {
835 Object.assign(opOptions, operation.arguments[key]);
836 if (opOptions.readPreference) {
837 opOptions.readPreference = normalizeReadPreference(opOptions.readPreference.mode);
838 }
839
840 return;
841 }
842
843 if (key === class="st">'readPreference') {
844 opOptions[key] = normalizeReadPreference(operation.arguments[key].mode);
845 return;
846 }
847

Callers 2

index.jsFile · 0.85
testOperationsFunction · 0.85

Calls 15

translateOperationNameFunction · 0.85
resolveOperationArgsFunction · 0.85
testOperationsFunction · 0.85
extractBulkRequestsFunction · 0.85
normalizeReadPreferenceFunction · 0.85
isTestRunnerCommandFunction · 0.85
promiseTryFunction · 0.85
escapeFunction · 0.85
extractCrudResultFunction · 0.85
unshiftMethod · 0.80
adminMethod · 0.80
applyMethod · 0.80

Tested by

no test coverage detected