Files
mongo/jstests/libs/override_methods/set_api_version.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

28 lines
1.0 KiB
JavaScript

/**
* Uses prototype overrides to set the apiVersion field to "1" for each command when running tests.
*/
import {OverrideHelpers} from "jstests/libs/override_methods/override_helpers.js";
const apiVersion = "1";
function runCommandWithApiVersion(conn, dbName, commandName, commandObj, func, makeFuncArgs) {
if (
commandObj.hasOwnProperty("apiVersion") ||
commandObj.hasOwnProperty("apiStrict") ||
commandObj.hasOwnProperty("apiDeprecationErrors")
) {
throw new Error(`Cowardly refusing to override API parameters of command ${tojson(commandObj)}`);
}
// We create a copy of 'commandObj' to avoid mutating the parameter the caller specified.
commandObj = Object.assign({}, commandObj);
// Set the API version on the command object.
commandObj.apiVersion = apiVersion;
return func.apply(conn, makeFuncArgs(commandObj));
}
OverrideHelpers.prependOverrideInParallelShell("jstests/libs/override_methods/set_api_version.js");
OverrideHelpers.overrideRunCommand(runCommandWithApiVersion);