Skip to content

Commit 95ad6bd

Browse files
committed
CXX-1665 Update CRUD tests and runner
1 parent 652fc75 commit 95ad6bd

File tree

10 files changed

+1814
-114
lines changed

10 files changed

+1814
-114
lines changed

data/crud/README.rst

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,28 @@
22
CRUD Tests
33
==========
44

5+
.. contents::
6+
7+
----
8+
9+
Introduction
10+
============
11+
512
The YAML and JSON files in this directory tree are platform-independent tests
6-
meant to exercise the translation from the API to underlying commands that
7-
MongoDB understands. Given the variety of languages and implementations and
8-
limited nature of a description of a test, there are a number of things that
9-
aren't testable. For instance, none of these tests assert that maxTimeMS was
10-
properly sent to the server. This would involve a lot of infrastructure to
11-
define and setup. Therefore, these YAML tests are in no way a replacement for
12-
more thorough testing. However, they can provide an initial verification of your
13+
that drivers can use to prove their conformance to the CRUD spec.
14+
15+
Given the variety of languages and implementations and limited nature of a
16+
description of a test, there are a number of things that aren't testable. For
17+
instance, none of these tests assert that maxTimeMS was properly sent to the
18+
server. This would involve a lot of infrastructure to define and setup.
19+
Therefore, these YAML tests are in no way a replacement for more thorough
20+
testing. However, they can provide an initial verification of your
1321
implementation.
1422

23+
Running these integration tests will require a running MongoDB server or
24+
cluster with server versions 2.6.0 or later. Some tests have specific server
25+
version requirements as noted by ``minServerVersion`` and ``maxServerVersion``.
26+
1527
Version
1628
=======
1729

@@ -43,32 +55,39 @@ Each YAML file has the following keys:
4355
- ``operation``: Document describing the operation to be executed. This will
4456
have the following fields:
4557

46-
- ``name``: The name of the operation as defined in the specification.
58+
- ``name``: The name of the operation as defined in the specification.
4759

48-
- ``arguments``: The names and values of arguments from the specification.
60+
- ``arguments``: The names and values of arguments from the specification.
4961

5062
- ``outcome``: Document describing the return value and/or expected state of
5163
the collection after the operation is executed. This will have some or all
5264
of the following fields:
5365

54-
- ``result``: The return value from the operation. Note that some tests
55-
specify an ``upsertedCount`` field when the server does not provide
56-
one in the result document. In these cases, an ``upsertedCount`` field
57-
with a value of 0 should be manually added to the document received
58-
from the server to facilitate comparison.
66+
- ``error``: If ``true``, the test should expect an error or exception. Note
67+
that some drivers may report server-side errors as a write error within a
68+
write result object.
69+
70+
- ``result``: The return value from the operation. This will correspond to
71+
an operation's result object as defined in the CRUD specification. This
72+
field may be omitted if ``error`` is ``true``. If this field is present
73+
and ``error`` is ``true`` (generally for multi-statement tests), the
74+
result reports information about operations that succeeded before an
75+
unrecoverable failure. In that case, drivers may choose to check the
76+
result object if their BulkWriteException (or equivalent) provides access
77+
to a write result object.
5978

60-
- ``collection``:
79+
- ``collection``:
6180

62-
- ``name`` (optional): The name of the collection to verify. If this
63-
isn't present then use the collection under test.
81+
- ``name`` (optional): The name of the collection to verify. If this isn't
82+
present then use the collection under test.
6483

65-
- ``data``: The data that should exist in the collection after the
66-
operation has been run.
84+
- ``data``: The data that should exist in the collection after the
85+
operation has been run.
6786

68-
Use as integration tests
69-
========================
87+
Expectations
88+
============
7089

71-
Running these as integration tests will require a running mongod server. Each of
72-
these tests is valid against a standalone mongod, a replica set, and a sharded
73-
system for server version 3.0 and later. Many of them will run against 2.6, but
74-
some will require conditional code.
90+
Expected results for some tests may include optional fields, such as
91+
``insertedId`` (for InsertOneResult), ``insertedIds`` (for InsertManyResult),
92+
and ``upsertedCount`` (for UpdateResult). Drivers that do not implement these
93+
fields can ignore them.

data/crud/test_files.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
./read/find-collation.json
1010
./read/find.json
1111
./write/bulkWrite-arrayFilters.json
12+
./write/bulkWrite-collation.json
13+
./write/bulkWrite.json
1214
./write/deleteMany-collation.json
1315
./write/deleteMany.json
1416
./write/deleteOne-collation.json
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
{
2+
"data": [
3+
{
4+
"_id": 1,
5+
"x": 11
6+
},
7+
{
8+
"_id": 2,
9+
"x": "ping"
10+
},
11+
{
12+
"_id": 3,
13+
"x": "pINg"
14+
},
15+
{
16+
"_id": 4,
17+
"x": "pong"
18+
},
19+
{
20+
"_id": 5,
21+
"x": "pONg"
22+
}
23+
],
24+
"minServerVersion": "3.4",
25+
"tests": [
26+
{
27+
"description": "BulkWrite with delete operations and collation",
28+
"operation": {
29+
"name": "bulkWrite",
30+
"arguments": {
31+
"requests": [
32+
{
33+
"name": "deleteOne",
34+
"arguments": {
35+
"filter": {
36+
"x": "PING"
37+
},
38+
"collation": {
39+
"locale": "en_US",
40+
"strength": 2
41+
}
42+
}
43+
},
44+
{
45+
"name": "deleteOne",
46+
"arguments": {
47+
"filter": {
48+
"x": "PING"
49+
},
50+
"collation": {
51+
"locale": "en_US",
52+
"strength": 2
53+
}
54+
}
55+
},
56+
{
57+
"name": "deleteMany",
58+
"arguments": {
59+
"filter": {
60+
"x": "PONG"
61+
},
62+
"collation": {
63+
"locale": "en_US",
64+
"strength": 2
65+
}
66+
}
67+
}
68+
],
69+
"options": {
70+
"ordered": true
71+
}
72+
}
73+
},
74+
"outcome": {
75+
"result": {
76+
"deletedCount": 4,
77+
"insertedCount": 0,
78+
"insertedIds": {},
79+
"matchedCount": 0,
80+
"modifiedCount": 0,
81+
"upsertedCount": 0,
82+
"upsertedIds": {}
83+
},
84+
"collection": {
85+
"data": [
86+
{
87+
"_id": 1,
88+
"x": 11
89+
}
90+
]
91+
}
92+
}
93+
},
94+
{
95+
"description": "BulkWrite with update operations and collation",
96+
"operation": {
97+
"name": "bulkWrite",
98+
"arguments": {
99+
"requests": [
100+
{
101+
"name": "updateMany",
102+
"arguments": {
103+
"filter": {
104+
"x": "ping"
105+
},
106+
"update": {
107+
"$set": {
108+
"x": "PONG"
109+
}
110+
},
111+
"collation": {
112+
"locale": "en_US",
113+
"strength": 3
114+
}
115+
}
116+
},
117+
{
118+
"name": "updateOne",
119+
"arguments": {
120+
"filter": {
121+
"x": "ping"
122+
},
123+
"update": {
124+
"$set": {
125+
"x": "PONG"
126+
}
127+
},
128+
"collation": {
129+
"locale": "en_US",
130+
"strength": 2
131+
}
132+
}
133+
},
134+
{
135+
"name": "replaceOne",
136+
"arguments": {
137+
"filter": {
138+
"x": "ping"
139+
},
140+
"replacement": {
141+
"_id": 6,
142+
"x": "ping"
143+
},
144+
"upsert": true,
145+
"collation": {
146+
"locale": "en_US",
147+
"strength": 3
148+
}
149+
}
150+
},
151+
{
152+
"name": "updateMany",
153+
"arguments": {
154+
"filter": {
155+
"x": "pong"
156+
},
157+
"update": {
158+
"$set": {
159+
"x": "PONG"
160+
}
161+
},
162+
"collation": {
163+
"locale": "en_US",
164+
"strength": 2
165+
}
166+
}
167+
}
168+
],
169+
"options": {
170+
"ordered": true
171+
}
172+
}
173+
},
174+
"outcome": {
175+
"result": {
176+
"deletedCount": 0,
177+
"insertedCount": 0,
178+
"insertedIds": {},
179+
"matchedCount": 6,
180+
"modifiedCount": 4,
181+
"upsertedCount": 1,
182+
"upsertedIds": {
183+
"2": 6
184+
}
185+
},
186+
"collection": {
187+
"data": [
188+
{
189+
"_id": 1,
190+
"x": 11
191+
},
192+
{
193+
"_id": 2,
194+
"x": "PONG"
195+
},
196+
{
197+
"_id": 3,
198+
"x": "PONG"
199+
},
200+
{
201+
"_id": 4,
202+
"x": "PONG"
203+
},
204+
{
205+
"_id": 5,
206+
"x": "PONG"
207+
},
208+
{
209+
"_id": 6,
210+
"x": "ping"
211+
}
212+
]
213+
}
214+
}
215+
}
216+
]
217+
}

0 commit comments

Comments
 (0)