Skip to content

Commit 84534c4

Browse files
committed
1 parent 4f89b79 commit 84534c4

File tree

4 files changed

+1414
-0
lines changed

4 files changed

+1414
-0
lines changed

source/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ HAS_JSYAML:
1717
echo 'Error: need "npm install -g js-yaml"' 1>&2; \
1818
exit 1; \
1919
fi
20+
21+
HAS_AJV:
22+
@if ! command -v ajv > /dev/null; then \
23+
echo 'Error: need "npm install -g ajv"' 1>&2; \
24+
exit 1; \
25+
fi
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"tests": [
3+
{
4+
"description": "valid because error:true and result has only expected fields",
5+
"operations": [
6+
{
7+
"object": "collection",
8+
"name": "runCommand",
9+
"error": true,
10+
"result": {
11+
"errorContains": "string"
12+
}
13+
}
14+
]
15+
},
16+
{
17+
"description": "valid because error == false. result can be any type (non-object)",
18+
"operations": [
19+
{
20+
"object": "collection",
21+
"name": "operation",
22+
"error": false,
23+
"result": 1
24+
}
25+
]
26+
},
27+
{
28+
"description": "valid because error == false. result can be any type (object)",
29+
"operations": [
30+
{
31+
"object": "collection",
32+
"name": "operation",
33+
"error": false,
34+
"result": {
35+
"foo": "bar"
36+
}
37+
}
38+
]
39+
},
40+
{
41+
"description": "valid because error != true. result can be any type (non-object)",
42+
"operations": [
43+
{
44+
"object": "collection",
45+
"name": "operation",
46+
"result": 1
47+
}
48+
]
49+
},
50+
{
51+
"description": "valid because error != true. result can be any type (object)",
52+
"operations": [
53+
{
54+
"object": "collection",
55+
"name": "operation",
56+
"result": {
57+
"foo": "bar"
58+
}
59+
}
60+
]
61+
}
62+
]
63+
}
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
4+
"type": "object",
5+
"title": "Unified Test Format",
6+
"description": "Schema definition for unified test format.",
7+
"additionalProperties": false,
8+
"required": ["tests"],
9+
"properties": {
10+
"runOn": {
11+
"type": "array",
12+
"description": "List of server version and/or topology requirements for which the tests can be run. If the test environment satisfies one or more of these requirements, the tests may be executed; otherwise, this file should be skipped. If this field is omitted, the tests can be assumed to have no particular requirements and should be executed.",
13+
"minItems": 1,
14+
"items": { "$ref": "#/definitions/runOnRequirement" }
15+
},
16+
17+
"databaseName": {
18+
"type": "string",
19+
"description": "Name of database under test. This is primarily useful when the database name must be referenced in an assertion."
20+
},
21+
22+
"collectionName": {
23+
"type": "string",
24+
"description": "Name of collection under test. This is primarily useful when the collection name must be referenced in an assertion."
25+
},
26+
27+
"initialData": {
28+
"type": "array",
29+
"description": "Data that should exist in collections before each test case is executed.",
30+
"minItems": 1,
31+
"items": { "$ref": "#/definitions/collectionData" }
32+
},
33+
34+
"tests": {
35+
"type": "array",
36+
"description": "Test cases.",
37+
"minItems": 1,
38+
"items": { "$ref": "#/definitions/test" }
39+
}
40+
},
41+
42+
"definitions": {
43+
"runOnRequirement": {
44+
"type": "object",
45+
"description": "A combination of server version and/or topology requirements for running the tests.",
46+
"additionalProperties": false,
47+
"minProperties": 1,
48+
"properties": {
49+
"maxServerVersion": {
50+
"type": "string",
51+
"description": "The maximum server version (inclusive) against which the tests can be run successfully. If this field is omitted, it should be assumed that there is no upper bound on the required server version.",
52+
"pattern": "^[0-9]+(\\.[0-9]+){1,2}$",
53+
"examples": ["4.0", "4.2.0"]
54+
},
55+
"minServerVersion": {
56+
"type": "string",
57+
"description": "The minimum server version (inclusive) required to successfully run the tests. If this field is omitted, it should be assumed that there is no lower bound on the required server version.",
58+
"pattern": "^[0-9]+(\\.[0-9]+){1,2}$",
59+
"examples": ["4.0", "4.2.0"]
60+
},
61+
"topology": {
62+
"type": "array",
63+
"description": "List of server topologies against which the tests can be run successfully. Valid topologies are \"single\", \"replicaset\", and \"sharded\". If this field is omitted, the default is all topologies.",
64+
"default": ["single", "replicaset", "sharded"],
65+
"minItems": 1,
66+
"items": {
67+
"type": "string",
68+
"enum": ["single", "replicaset", "sharded"]
69+
}
70+
}
71+
}
72+
},
73+
74+
"collectionData": {
75+
"type": "object",
76+
"description": "List of documents that should correspond to the contents of a collection.",
77+
"additionalProperties": false,
78+
"required": ["documents"],
79+
"properties": {
80+
"collection": {
81+
"type": "string",
82+
"description": "Collection name. If omitted, this defaults to the collection under test."
83+
},
84+
"database": {
85+
"type": "string",
86+
"description": "Database name. If omitted, this defaults to the database under test."
87+
},
88+
"documents": {
89+
"type": "array",
90+
"description": "List of documents corresponding to the contents of the collection. This list may be empty.",
91+
"items": { "type": "object" }
92+
}
93+
}
94+
},
95+
96+
"event": {
97+
"type": "object",
98+
"description": "An event (e.g. APM, SDAM) to be observed while running the test operations.",
99+
"additionalProperties": false,
100+
"minProperties": 1,
101+
"maxProperties": 1,
102+
"properties": {
103+
"commandStartedEvent": {
104+
"type": "object",
105+
"additionalProperties": false,
106+
"minProperties": 1,
107+
"properties": {
108+
"command": { "type": "object" },
109+
"commandName": { "type": "string" },
110+
"databaseName": { "type": "string" }
111+
}
112+
}
113+
}
114+
},
115+
116+
"collectionOrDatabaseOptions": {
117+
"type": "object",
118+
"description": "Map of parameters to pass when creating a collection or database.",
119+
"additionalProperties": false,
120+
"properties": {
121+
"readConcern": { "type": "object" },
122+
"readPreference": { "type": "object" },
123+
"writeConcern": { "type": "object" }
124+
}
125+
},
126+
127+
"operation": {
128+
"type": "object",
129+
"description": "An operation to be executed as part of the test.",
130+
"additionalProperties": false,
131+
"required": ["name"],
132+
"properties": {
133+
"name": {
134+
"type": "string",
135+
"description": "Name of the operation (e.g. method) to perform on the object."
136+
},
137+
"object": {
138+
"type": "string",
139+
"description": "Name of the object on which to perform the operation.",
140+
"default": "collection",
141+
"enum": ["collection", "database", "session0", "session1", "testRunner"]
142+
},
143+
"collectionOptions": { "$ref": "#/definitions/collectionOrDatabaseOptions" },
144+
"databaseOptions": { "$ref": "#/definitions/collectionOrDatabaseOptions" },
145+
"command_name": {
146+
"type": "string",
147+
"description": "Required only when name is \"runCommand\". The name of the command to run. This may be used by languages that are unable preserve the order of keys in the command argument when parsing YAML or JSON."
148+
},
149+
"arguments": {
150+
"type": "object",
151+
"description": "Map of parameter names and values for the operation."
152+
},
153+
"error": {
154+
"type": "boolean",
155+
"description": "If true, the test should expect the operation to raise an error/exception. This could be either a server-generated or a driver-generated error.",
156+
"default": false
157+
},
158+
"result": {
159+
"description": "The return value from the operation, if any. This field may be a scalar value, a single document, or an array of documents in the case of a multi-document read. If the operation is expected to return an error, the result is a single document containing several \"error\" fields defined in a conditional schema."
160+
}
161+
},
162+
"allOf": [
163+
{
164+
"$comment": "Require command_name for runCommand operations",
165+
"oneOf": [
166+
{
167+
"properties": { "name": { "const": "runCommand" }},
168+
"required": ["command_name"]
169+
},
170+
{
171+
"properties": { "name": { "not": { "const": "runCommand" }}}
172+
}
173+
]
174+
},
175+
{
176+
"$comment": "Conditional result schema when error is true",
177+
"anyOf": [
178+
{ "properties": { "error": false }},
179+
{ "properties": { "error": { "const": false }}},
180+
{
181+
"properties": {
182+
"error": { "const": true },
183+
"result": {
184+
"type": "object",
185+
"additionalProperties": false,
186+
"minProperties": 1,
187+
"properties": {
188+
"errorContains": {
189+
"type": "string",
190+
"description": "A substring of the expected error message."
191+
},
192+
"errorCodeName": {
193+
"type": "string",
194+
"description": "The expected \"codeName\" field in the server error response."
195+
},
196+
"errorLabelsContain": {
197+
"type": "array",
198+
"description": "A list of error label strings that the error is expected to have.",
199+
"items": { "type": "string" }
200+
},
201+
"errorLabelsOmit": {
202+
"type": "array",
203+
"description": "A list of error label strings that the error is expected not to have.",
204+
"items": { "type": "string" }
205+
}
206+
}
207+
}
208+
}
209+
}
210+
]
211+
}
212+
]
213+
},
214+
215+
"test": {
216+
"type": "object",
217+
"description": "Test case consisting of a sequence of operations to be executed. The test may optionally include configuration directives and event/outcome assertions.",
218+
"required": ["description", "operations"],
219+
"properties": {
220+
"description": {
221+
"type": "string",
222+
"description": "The name of the test."
223+
},
224+
"skipReason": {
225+
"type": "string",
226+
"description": "If set, the test will be skipped. The string should explain the reason for skipping the test (e.g. JIRA ticket)."
227+
},
228+
"useMultipleMongoses": {
229+
"type": "boolean",
230+
"description": "If true, the MongoClient for this test should be initialized with multiple mongos seed addresses. If false or omitted, only a single mongos address should be specified. This field has no effect for non-sharded topologies."
231+
},
232+
"clientOptions": {
233+
"$comment": "TODO: this schema is not sufficient for expressing multiple readPreferenceTags, since keys would repeat",
234+
"type": "object",
235+
"description": "Additional connection string options to pass to the MongoClient constructor.",
236+
"additionalProperties": {
237+
"type": ["number", "string"]
238+
}
239+
},
240+
"failPoint": {
241+
"type": "object",
242+
"description": "A server failpoint to enable expressed as a complete configureFailPoint command to run on the admin database. This option and useMultipleMongoses:true are mutually exclusive.",
243+
"additionalProperties": false,
244+
"required": ["configureFailPoint", "mode"],
245+
"properties": {
246+
"configureFailPoint": { "type": "string" },
247+
"mode": { "type": ["object", "string"] },
248+
"data": { "type": "object" }
249+
}
250+
},
251+
"sessionOptions": {
252+
"type": "object",
253+
"description": " Map of session names (e.g. \"session0\") to documents, each of which denotes parameters to pass to MongoClient.startSession() when creating that session.",
254+
"additionalProperties": false,
255+
"patternProperties": {
256+
"^session[0-1]$": { "type": "object" }
257+
}
258+
},
259+
"operations": {
260+
"type": "array",
261+
"description": "List of operations to be executed for the test case.",
262+
"items": { "$ref": "#/definitions/operation" }
263+
},
264+
"expectedEvents": {
265+
"type": "array",
266+
"description": "List of events, which are expected to be observed in this order by running the operations.",
267+
"items": { "$ref": "#/definitions/event" }
268+
},
269+
"outcome": {
270+
"type": "array",
271+
"description": "Data that should exist in collections after all operations have been executed. The list of documents should be sorted ascendingly by the \"_id\" field to allow for deterministic comparisons.",
272+
"minItems": 1,
273+
"items": { "$ref": "#/definitions/collectionData" }
274+
}
275+
},
276+
"allOf": [
277+
{
278+
"$comment": "useMultipleMongoses:true and failPoint are mutually exclusive",
279+
"if": { "properties": { "useMultipleMongoses": { "const": true }}},
280+
"then": { "properties": { "failPoint": { "not": { "type": "object" }}}}
281+
}
282+
]
283+
}
284+
}
285+
}

0 commit comments

Comments
 (0)