Skip to content

Commit e23b305

Browse files
committed
Updated CRUD tests
SCALA-487
1 parent 22e4f5e commit e23b305

Some content is hidden

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

44 files changed

+2708
-789
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
==========
2+
CRUD Tests
3+
==========
4+
5+
.. contents::
6+
7+
----
8+
9+
Introduction
10+
============
11+
12+
The YAML and JSON files in this directory tree are platform-independent tests
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
21+
implementation.
22+
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+
27+
Version
28+
=======
29+
30+
Files in the "specifications" repository have no version scheme. They are not
31+
tied to a MongoDB server version.
32+
33+
Format
34+
======
35+
36+
Each YAML file has the following keys:
37+
38+
- ``database_name`` (optional): The database to use for testing.
39+
40+
- ``data``: The data that should exist in the collection under test before each
41+
test run.
42+
43+
- ``minServerVersion`` (optional): The minimum server version (inclusive)
44+
required to successfully run the test. If this field is not present, it should
45+
be assumed that there is no lower bound on the required server version.
46+
47+
- ``maxServerVersion`` (optional): The maximum server version (exclusive)
48+
against which this test can run successfully. If this field is not present,
49+
it should be assumed that there is no upper bound on the required server
50+
version.
51+
52+
- ``tests``: An array of tests that are to be run independently of each other.
53+
Each test will have some or all of the following fields:
54+
55+
- ``description``: The name of the test.
56+
57+
- ``operation``: Document describing the operation to be executed. This will
58+
have the following fields:
59+
60+
- ``name``: The name of the operation as defined in the specification. The
61+
name `db-aggregate` refers to database-level aggregation.
62+
63+
- ``object``: The name of the object to perform the operation on. Can be
64+
"database" or "collection". Defaults to "collection" if undefined.
65+
66+
- ``arguments``: The names and values of arguments from the specification.
67+
68+
- ``outcome``: Document describing the return value and/or expected state of
69+
the collection after the operation is executed. This will have some or all
70+
of the following fields:
71+
72+
- ``error``: If ``true``, the test should expect an error or exception. Note
73+
that some drivers may report server-side errors as a write error within a
74+
write result object.
75+
76+
- ``result``: The return value from the operation. This will correspond to
77+
an operation's result object as defined in the CRUD specification. This
78+
field may be omitted if ``error`` is ``true``. If this field is present
79+
and ``error`` is ``true`` (generally for multi-statement tests), the
80+
result reports information about operations that succeeded before an
81+
unrecoverable failure. In that case, drivers may choose to check the
82+
result object if their BulkWriteException (or equivalent) provides access
83+
to a write result object.
84+
85+
- ``collection``:
86+
87+
- ``name`` (optional): The name of the collection to verify. If this isn't
88+
present then use the collection under test.
89+
90+
- ``data``: The data that should exist in the collection after the
91+
operation has been run.
92+
93+
Expectations
94+
============
95+
96+
Expected results for some tests may include optional fields, such as
97+
``insertedId`` (for InsertOneResult), ``insertedIds`` (for InsertManyResult),
98+
and ``upsertedCount`` (for UpdateResult). Drivers that do not implement these
99+
fields can ignore them.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"database_name": "admin",
3+
"data": [],
4+
"minServerVersion": "3.6",
5+
"tests": [
6+
{
7+
"description": "Aggregate with $currentOp",
8+
"operation": {
9+
"name": "aggregate",
10+
"object": "database",
11+
"arguments": {
12+
"pipeline": [
13+
{
14+
"$currentOp": {
15+
"allUsers": false,
16+
"idleConnections": false
17+
}
18+
},
19+
{
20+
"$match": {
21+
"command.aggregate": {
22+
"$eq": 1
23+
}
24+
}
25+
},
26+
{
27+
"$project": {
28+
"command": 1
29+
}
30+
},
31+
{
32+
"$project": {
33+
"command.lsid": 0
34+
}
35+
}
36+
]
37+
}
38+
},
39+
"outcome": {
40+
"result": [
41+
{
42+
"command": {
43+
"aggregate": 1,
44+
"pipeline": [
45+
{
46+
"$currentOp": {
47+
"allUsers": false,
48+
"idleConnections": false
49+
}
50+
},
51+
{
52+
"$match": {
53+
"command.aggregate": {
54+
"$eq": 1
55+
}
56+
}
57+
},
58+
{
59+
"$project": {
60+
"command": 1
61+
}
62+
},
63+
{
64+
"$project": {
65+
"command.lsid": 0
66+
}
67+
}
68+
],
69+
"cursor": {},
70+
"$db": "admin"
71+
}
72+
}
73+
]
74+
}
75+
},
76+
{
77+
"description": "Aggregate with $currentOp and allowDiskUse",
78+
"operation": {
79+
"name": "aggregate",
80+
"object": "database",
81+
"arguments": {
82+
"pipeline": [
83+
{
84+
"$currentOp": {
85+
"allUsers": true,
86+
"idleConnections": true
87+
}
88+
},
89+
{
90+
"$match": {
91+
"command.aggregate": {
92+
"$eq": 1
93+
}
94+
}
95+
},
96+
{
97+
"$project": {
98+
"command": 1
99+
}
100+
},
101+
{
102+
"$project": {
103+
"command.lsid": 0
104+
}
105+
}
106+
],
107+
"allowDiskUse": true
108+
}
109+
},
110+
"outcome": {
111+
"result": [
112+
{
113+
"command": {
114+
"aggregate": 1,
115+
"pipeline": [
116+
{
117+
"$currentOp": {
118+
"allUsers": true,
119+
"idleConnections": true
120+
}
121+
},
122+
{
123+
"$match": {
124+
"command.aggregate": {
125+
"$eq": 1
126+
}
127+
}
128+
},
129+
{
130+
"$project": {
131+
"command": 1
132+
}
133+
},
134+
{
135+
"$project": {
136+
"command.lsid": 0
137+
}
138+
}
139+
],
140+
"allowDiskUse": true,
141+
"cursor": {},
142+
"$db": "admin"
143+
}
144+
}
145+
]
146+
}
147+
}
148+
]
149+
}

driver/src/it/resources/crud/read/aggregate-collation.json

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
}
3636
}
3737
]
38-
}
38+
}

driver/src/it/resources/crud/read/aggregate-out.json

100755100644
Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,57 @@
6565
]
6666
}
6767
}
68+
},
69+
{
70+
"description": "Aggregate with $out and batch size of 0",
71+
"operation": {
72+
"name": "aggregate",
73+
"arguments": {
74+
"pipeline": [
75+
{
76+
"$sort": {
77+
"x": 1
78+
}
79+
},
80+
{
81+
"$match": {
82+
"_id": {
83+
"$gt": 1
84+
}
85+
}
86+
},
87+
{
88+
"$out": "other_test_collection"
89+
}
90+
],
91+
"batchSize": 0
92+
}
93+
},
94+
"outcome": {
95+
"result": [
96+
{
97+
"_id": 2,
98+
"x": 22
99+
},
100+
{
101+
"_id": 3,
102+
"x": 33
103+
}
104+
],
105+
"collection": {
106+
"name": "other_test_collection",
107+
"data": [
108+
{
109+
"_id": 2,
110+
"x": 22
111+
},
112+
{
113+
"_id": 3,
114+
"x": 33
115+
}
116+
]
117+
}
118+
}
68119
}
69120
]
70-
}
121+
}

driver/src/it/resources/crud/read/aggregate.json

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@
5050
}
5151
}
5252
]
53-
}
53+
}

driver/src/it/resources/crud/read/count-collation.json

100755100644
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,25 @@
88
"minServerVersion": "3.4",
99
"tests": [
1010
{
11-
"description": "Count with collation",
11+
"description": "Count documents with collation",
12+
"operation": {
13+
"name": "countDocuments",
14+
"arguments": {
15+
"filter": {
16+
"x": "ping"
17+
},
18+
"collation": {
19+
"locale": "en_US",
20+
"strength": 2
21+
}
22+
}
23+
},
24+
"outcome": {
25+
"result": 1
26+
}
27+
},
28+
{
29+
"description": "Deprecated count with collation",
1230
"operation": {
1331
"name": "count",
1432
"arguments": {
@@ -26,4 +44,4 @@
2644
}
2745
}
2846
]
29-
}
47+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"data": [],
3+
"tests": [
4+
{
5+
"description": "Estimated document count with empty collection",
6+
"operation": {
7+
"name": "estimatedDocumentCount",
8+
"arguments": {}
9+
},
10+
"outcome": {
11+
"result": 0
12+
}
13+
},
14+
{
15+
"description": "Count documents with empty collection",
16+
"operation": {
17+
"name": "countDocuments",
18+
"arguments": {
19+
"filter": {}
20+
}
21+
},
22+
"outcome": {
23+
"result": 0
24+
}
25+
},
26+
{
27+
"description": "Deprecated count with empty collection",
28+
"operation": {
29+
"name": "count",
30+
"arguments": {
31+
"filter": {}
32+
}
33+
},
34+
"outcome": {
35+
"result": 0
36+
}
37+
}
38+
]
39+
}

0 commit comments

Comments
 (0)