Skip to content

Commit 8c35196

Browse files
committed
Add unified test format test files
1 parent 1953dcc commit 8c35196

File tree

163 files changed

+7717
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+7717
-0
lines changed
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
4+
"title": "Unified Test Format",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"required": ["description", "schemaVersion", "tests"],
8+
"properties": {
9+
"description": { "type": "string" },
10+
"schemaVersion": { "$ref": "#/definitions/version" },
11+
"runOnRequirements": {
12+
"type": "array",
13+
"minItems": 1,
14+
"items": { "$ref": "#/definitions/runOnRequirement" }
15+
},
16+
"createEntities": {
17+
"type": "array",
18+
"minItems": 1,
19+
"items": { "$ref": "#/definitions/entity" }
20+
},
21+
"initialData": {
22+
"type": "array",
23+
"minItems": 1,
24+
"items": { "$ref": "#/definitions/collectionData" }
25+
},
26+
"tests": {
27+
"type": "array",
28+
"minItems": 1,
29+
"items": { "$ref": "#/definitions/test" }
30+
}
31+
},
32+
33+
"definitions": {
34+
"version": {
35+
"type": "string",
36+
"pattern": "^[0-9]+(\\.[0-9]+){1,2}$"
37+
},
38+
39+
"runOnRequirement": {
40+
"type": "object",
41+
"additionalProperties": false,
42+
"minProperties": 1,
43+
"properties": {
44+
"maxServerVersion": { "$ref": "#/definitions/version" },
45+
"minServerVersion": { "$ref": "#/definitions/version" },
46+
"topologies": {
47+
"type": "array",
48+
"minItems": 1,
49+
"items": {
50+
"type": "string",
51+
"enum": ["single", "replicaset", "sharded", "sharded-replicaset"]
52+
}
53+
}
54+
}
55+
},
56+
57+
"entity": {
58+
"type": "object",
59+
"additionalProperties": false,
60+
"maxProperties": 1,
61+
"minProperties": 1,
62+
"properties": {
63+
"client": {
64+
"type": "object",
65+
"additionalProperties": false,
66+
"required": ["id"],
67+
"properties": {
68+
"id": { "type": "string" },
69+
"uriOptions": { "type": "object" },
70+
"useMultipleMongoses": { "type": "boolean" },
71+
"observeEvents": {
72+
"type": "array",
73+
"minItems": 1,
74+
"items": {
75+
"type": "string",
76+
"enum": ["commandStartedEvent", "commandSucceededEvent", "commandFailedEvent"]
77+
}
78+
},
79+
"ignoreCommandMonitoringEvents": {
80+
"type": "array",
81+
"minItems": 1,
82+
"items": { "type": "string" }
83+
}
84+
}
85+
},
86+
"database": {
87+
"type": "object",
88+
"additionalProperties": false,
89+
"required": ["id", "client", "databaseName"],
90+
"properties": {
91+
"id": { "type": "string" },
92+
"client": { "type": "string" },
93+
"databaseName": { "type": "string" },
94+
"databaseOptions": { "$ref": "#/definitions/collectionOrDatabaseOptions" }
95+
}
96+
},
97+
"collection": {
98+
"type": "object",
99+
"additionalProperties": false,
100+
"required": ["id", "database", "collectionName"],
101+
"properties": {
102+
"id": { "type": "string" },
103+
"database": { "type": "string" },
104+
"collectionName": { "type": "string" },
105+
"collectionOptions": { "$ref": "#/definitions/collectionOrDatabaseOptions" }
106+
}
107+
},
108+
"session": {
109+
"type": "object",
110+
"additionalProperties": false,
111+
"required": ["id", "client"],
112+
"properties": {
113+
"id": { "type": "string" },
114+
"client": { "type": "string" },
115+
"sessionOptions": { "type": "object" }
116+
}
117+
},
118+
"bucket": {
119+
"type": "object",
120+
"additionalProperties": false,
121+
"required": ["id", "database"],
122+
"properties": {
123+
"id": { "type": "string" },
124+
"database": { "type": "string" },
125+
"bucketOptions": { "type": "object" }
126+
}
127+
},
128+
"stream": {
129+
"type": "object",
130+
"additionalProperties": false,
131+
"required": ["id", "hexBytes"],
132+
"properties": {
133+
"id": { "type": "string" },
134+
"hexBytes": {
135+
"type": "string",
136+
"pattern": "^([0-9A-Fa-f]{2})*$"
137+
}
138+
}
139+
}
140+
}
141+
},
142+
143+
"collectionData": {
144+
"type": "object",
145+
"additionalProperties": false,
146+
"required": ["collectionName", "databaseName", "documents"],
147+
"properties": {
148+
"collectionName": { "type": "string" },
149+
"databaseName": { "type": "string" },
150+
"documents": {
151+
"type": "array",
152+
"items": { "type": "object" }
153+
}
154+
}
155+
},
156+
157+
"expectedEventsForClient": {
158+
"type": "object",
159+
"additionalProperties": false,
160+
"required": ["client", "events"],
161+
"properties": {
162+
"client": { "type": "string" },
163+
"events": {
164+
"type": "array",
165+
"items": { "$ref": "#/definitions/expectedEvent" }
166+
}
167+
}
168+
},
169+
170+
"expectedEvent": {
171+
"type": "object",
172+
"additionalProperties": false,
173+
"maxProperties": 1,
174+
"minProperties": 1,
175+
"properties": {
176+
"commandStartedEvent": {
177+
"type": "object",
178+
"additionalProperties": false,
179+
"properties": {
180+
"command": { "type": "object" },
181+
"commandName": { "type": "string" },
182+
"databaseName": { "type": "string" }
183+
}
184+
},
185+
"commandSucceededEvent": {
186+
"type": "object",
187+
"additionalProperties": false,
188+
"properties": {
189+
"reply": { "type": "object" },
190+
"commandName": { "type": "string" }
191+
}
192+
},
193+
"commandFailedEvent": {
194+
"type": "object",
195+
"additionalProperties": false,
196+
"properties": {
197+
"commandName": { "type": "string" }
198+
}
199+
}
200+
}
201+
},
202+
203+
"collectionOrDatabaseOptions": {
204+
"type": "object",
205+
"additionalProperties": false,
206+
"properties": {
207+
"readConcern": { "type": "object" },
208+
"readPreference": { "type": "object" },
209+
"writeConcern": { "type": "object" }
210+
}
211+
},
212+
213+
"operation": {
214+
"type": "object",
215+
"additionalProperties": false,
216+
"required": ["name", "object"],
217+
"properties": {
218+
"name": { "type": "string" },
219+
"object": { "type": "string" },
220+
"arguments": { "type": "object" },
221+
"expectError": { "$ref": "#/definitions/expectedError" },
222+
"expectResult": {},
223+
"saveResultAsEntity": { "type": "string" }
224+
},
225+
"allOf": [
226+
{ "not": { "required": ["expectError", "expectResult"] } },
227+
{ "not": { "required": ["expectError", "saveResultAsEntity"] } }
228+
]
229+
},
230+
231+
"expectedError": {
232+
"type": "object",
233+
"additionalProperties": false,
234+
"minProperties": 1,
235+
"properties": {
236+
"isError": {
237+
"type": "boolean",
238+
"const": true
239+
},
240+
"isClientError": { "type": "boolean" },
241+
"errorContains": { "type": "string" },
242+
"errorCode": { "type": "integer" },
243+
"errorCodeName": { "type": "string" },
244+
"errorLabelsContain": {
245+
"type": "array",
246+
"minItems": 1,
247+
"items": { "type": "string" }
248+
},
249+
"errorLabelsOmit": {
250+
"type": "array",
251+
"minItems": 1,
252+
"items": { "type": "string" }
253+
},
254+
"expectResult": {}
255+
}
256+
},
257+
258+
"test": {
259+
"type": "object",
260+
"additionalProperties": false,
261+
"required": ["description", "operations"],
262+
"properties": {
263+
"description": { "type": "string" },
264+
"runOnRequirements": {
265+
"type": "array",
266+
"minItems": 1,
267+
"items": { "$ref": "#/definitions/runOnRequirement" }
268+
},
269+
"skipReason": { "type": "string" },
270+
"operations": {
271+
"type": "array",
272+
"items": { "$ref": "#/definitions/operation" }
273+
},
274+
"expectEvents": {
275+
"type": "array",
276+
"items": { "$ref": "#/definitions/expectedEventsForClient" }
277+
},
278+
"outcome": {
279+
"type": "array",
280+
"minItems": 1,
281+
"items": { "$ref": "#/definitions/collectionData" }
282+
}
283+
}
284+
}
285+
}
286+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
=========================
2+
Unified Test Format Tests
3+
=========================
4+
5+
.. contents::
6+
7+
----
8+
9+
Introduction
10+
============
11+
12+
This directory contains tests for the Unified Test Format's schema and test
13+
runner implementation(s). Tests are organized in the following directories:
14+
15+
- ``invalid``: These files do not validate against the schema and are used to
16+
test the schema itself.
17+
18+
- ``valid-pass``: These files validate against the schema and should pass when
19+
executed with a test runner.
20+
21+
- ``valid-fail``: These files validate against the schema but should produce
22+
runtime errors or failures when executed with a test runner. Some do so by
23+
violating the "SHOULD" and "SHOULD NOT" guidance in the spec (e.g. referencing
24+
an undefined entity).
25+
26+
Validating Test Files
27+
=====================
28+
29+
JSON and YAML test files can be validated using `Ajv <https://ajv.js.org/>`__
30+
and a schema from the parent directory (e.g. ``schema-1.0.json``).
31+
32+
Test files can be validated individually like so::
33+
34+
ajv -s ../schema-1.0.json -d path/to/test.yml
35+
36+
Ajv can also be used to assert the validity of test files::
37+
38+
ajv test -s ../schema-1.0.json -d "invalid/*.yml" --invalid
39+
ajv test -s ../schema-1.0.json -d "valid-*/*.yml" --valid

0 commit comments

Comments
 (0)