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
84
85
86
87
88
|
"use strict";
/**
* Helper functions that help make assertions on API Version parameters.
*/
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 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,
assertViewFailsWithAPIStrict: assertViewFailsWithAPIStrict,
assertViewSucceedsWithAPIStrict: assertViewSucceedsWithAPIStrict,
};
})();
|