1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/**
* Checks that commands included/omitted in API V1 behave correctly with various combinations of API
* parameters.
*
* @tags: [
* requires_non_retryable_commands,
* uses_api_parameters,
* ]
*/
(function() {
"use strict";
let counter = 0;
const counter_fun = function() {
return `APIV1-${counter}`;
};
const testDB = db.getSiblingDB(jsTestName());
const testColl = testDB.getCollection("test");
function runTest({cmd, apiVersion1, apiStrict, apiDeprecationErrors}) {
// Instantiate "cmd" so we can modify it.
let copy = cmd();
jsTestLog(
`Test ${tojson(copy)}, which is ${apiVersion1 ? "in" : "not in"} API V1, with apiStrict = ${
apiStrict} and apiDeprecationErrors = ${apiDeprecationErrors}`);
copy.apiVersion = "1";
copy.apiStrict = apiStrict;
copy.apiDeprecationErrors = apiDeprecationErrors;
if (!apiVersion1 && apiStrict) {
assert.commandFailedWithCode(
testDB.runCommand(copy),
ErrorCodes.APIStrictError,
"Provided apiStrict: true, but the invoked command's apiVersions() does not include \"1\"");
} else {
assert.commandWorked(testDB.runCommand(copy));
}
}
const commands = [
{cmd: () => ({buildInfo: 1}), apiVersion1: false},
{cmd: () => ({createUser: counter_fun(), pwd: "pwd", roles: []}), apiVersion1: false},
{cmd: () => ({dropUser: counter_fun()}), apiVersion1: false},
{cmd: () => ({serverStatus: 1}), apiVersion1: false},
{cmd: () => ({usersInfo: 1}), apiVersion1: false},
{cmd: () => ({aggregate: testColl.getName(), pipeline: [], cursor: {}}), apiVersion1: true},
{cmd: () => ({count: "system.js"}), apiVersion1: true},
{cmd: () => ({create: counter_fun()}), apiVersion1: true},
{cmd: () => ({find: counter_fun()}), apiVersion1: true},
{
cmd: () => ({insert: "APIV1-0", documents: [{_id: counter_fun(), cast: "jonSnow"}]}),
apiVersion1: true
},
{
cmd: () => ({
update: "APIV1-0",
updates: [{q: {_id: counter_fun()}, u: {$set: {cast: "aryaStark"}}}]
}),
apiVersion1: true,
},
{
cmd: () => ({delete: "APIV1-0", deletes: [{q: {_id: counter_fun()}, limit: 1}]}),
apiVersion1: true
},
{cmd: () => ({drop: counter_fun()}), apiVersion1: true}
];
for (let {cmd, apiVersion1} of commands) {
counter = 0;
for (let apiStrict of [false, true]) {
for (let apiDeprecationErrors of [false, true]) {
runTest({
cmd: cmd,
apiVersion1: apiVersion1,
apiStrict: apiStrict,
apiDeprecationErrors: apiDeprecationErrors
});
counter += 1;
}
}
}
})();
|