Files
mongo/jstests/libs/api_version_helpers.js
Mariano Shaar b00601c125 SERVER-94659 Test $sigmoid query shape and stable API restrictions (#28683)
GitOrigin-RevId: 00d91fdb8ea72e665d570d831c29a63afd1ecbef
2024-10-31 22:09:16 +00:00

103 lines
3.5 KiB
JavaScript

/**
* Helper functions that help make assertions on API Version parameters.
*/
export var APIVersionHelpers = (function() {
/**
* Asserts that the pipeline fails with the given code when apiStrict is set to true and
* apiVersion is "1".
*/
function assertAggregateFailsWithAPIStrict(pipeline, collName, errorCodes) {
assert.commandFailedWithCode(db.runCommand({
aggregate: collName,
pipeline: pipeline,
cursor: {},
apiStrict: true,
apiVersion: "1"
}),
errorCodes,
pipeline);
}
/**
* Asserts that the pipeline succeeds when apiStrict is set to true and apiVersion is "1".
*/
function assertAggregateSucceedsWithAPIStrict(pipeline, collName, errorCodes) {
if (errorCodes) {
assert.commandWorkedOrFailedWithCode(db.runCommand({
aggregate: collName,
pipeline: pipeline,
cursor: {},
apiStrict: true,
apiVersion: "1"
}),
errorCodes,
pipeline);
} else {
assert.commandWorked(db.runCommand({
aggregate: collName,
pipeline: pipeline,
cursor: {},
apiStrict: true,
apiVersion: "1"
}),
pipeline);
}
}
/**
* Asserts that the pipeline succeeds with the given code when apiStrict is set to false and
* apiVersion is "1".
*/
function assertAggregateSucceedsAPIVersionWithoutAPIStrict(pipeline, collName) {
assert.commandWorked(db.runCommand({
aggregate: collName,
pipeline: pipeline,
cursor: {},
apiStrict: false,
apiVersion: "1"
}),
pipeline);
}
/**
* Asserts that the given pipeline cannot be used to define a view when apiStrict is set to true
* and apiVersion is "1" on the create command.
*/
function assertViewFailsWithAPIStrict(pipeline, viewName, collName) {
assert.commandFailedWithCode(db.runCommand({
create: viewName,
viewOn: collName,
pipeline: pipeline,
apiStrict: true,
apiVersion: "1"
}),
ErrorCodes.APIStrictError,
pipeline);
}
/**
* Asserts that the given pipeline can be used to define a view when apiStrict is set to true
* and apiVersion is "1" on the create command.
*/
function assertViewSucceedsWithAPIStrict(pipeline, viewName, collName) {
assert.commandWorked(db.runCommand({
create: viewName,
viewOn: collName,
pipeline: pipeline,
apiStrict: true,
apiVersion: "1"
}));
assert.commandWorked(db.runCommand({drop: viewName}));
}
return {
assertAggregateFailsWithAPIStrict: assertAggregateFailsWithAPIStrict,
assertAggregateSucceedsWithAPIStrict: assertAggregateSucceedsWithAPIStrict,
assertAggregateSucceedsAPIVersionWithoutAPIStrict:
assertAggregateSucceedsAPIVersionWithoutAPIStrict,
assertViewFailsWithAPIStrict: assertViewFailsWithAPIStrict,
assertViewSucceedsWithAPIStrict: assertViewSucceedsWithAPIStrict,
};
})();