Skip to content

Commit 4badd8d

Browse files
committed
CSHARP-1813: Resync CRUD spec tests.
1 parent 1e4304e commit 4badd8d

File tree

113 files changed

+6330
-3935
lines changed

Some content is hidden

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

113 files changed

+6330
-3935
lines changed

tests/MongoDB.Driver.Core.TestHelpers/XunitExtensions/RequireServer.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,20 @@ public RequireServer VersionLessThan(string version)
161161
{
162162
return VersionLessThan(SemanticVersion.Parse(version));
163163
}
164+
165+
public RequireServer VersionLessThanOrEqualTo(SemanticVersion version)
166+
{
167+
var actualVersion = CoreTestConfiguration.ServerVersion;
168+
if (actualVersion <= version)
169+
{
170+
return this;
171+
}
172+
throw new SkipTestException($"Test skipped because server version {actualVersion} is not less than or equal to {version}.");
173+
}
174+
175+
public RequireServer VersionLessThanOrEqualTo(string version)
176+
{
177+
return VersionLessThanOrEqualTo(SemanticVersion.Parse(version));
178+
}
164179
}
165180
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
==========
2+
CRUD Tests
3+
==========
4+
5+
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
9+
that aren't testable. For instance, none of these tests assert that maxTimeMS
10+
was 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
13+
your implementation.
14+
15+
16+
Converting to JSON
17+
==================
18+
19+
The tests are written in YAML
20+
because it is easier for humans to write and read,
21+
and because YAML includes a standard comment format.
22+
A JSONified version of each YAML file is included in this repository.
23+
Whenever you change the YAML, re-convert to JSON.
24+
One method to convert to JSON is using
25+
`yamljs <https://www.npmjs.com/package/yamljs>`_::
26+
27+
npm install -g yamljs
28+
yaml2json -s -p -r .
29+
30+
31+
Version
32+
=======
33+
34+
Files in the "specifications" repository have no version scheme.
35+
They are not tied to a MongoDB server version,
36+
and it is our intention that each specification moves from "draft" to "final"
37+
with no further revisions; it is superseded by a future spec, not revised.
38+
39+
However, implementers must have stable sets of tests to target.
40+
As test files evolve they will occasionally be tagged like
41+
"crud-tests-YYYY-MM-DD", until the spec is final.
42+
43+
Format
44+
======
45+
46+
Each YAML file has the following keys:
47+
48+
- data: The data that should exist in the collection under test before each test run.
49+
- minServerVersion: OPTIONAL: The minimum server version required to successfully run the test. If this field is not
50+
present, it should be assumed that there is no lower bound on the server version required.
51+
- maxServerVersion: OPTIONAL: The max server version against which this test can run successfully. If this field is not
52+
present, it should be assumed that there is no upper bound on the server version required.
53+
- tests:
54+
An array of tests that are to be run independently of each other. Each test will
55+
have some or all of the following fields
56+
57+
- description: The name of the test
58+
- operation:
59+
60+
- name: The name of the operation as defined in the specification.
61+
- arguments: The names and values of arguments from the specification.
62+
- outcome:
63+
64+
- result: The return value from the operation.
65+
- collection:
66+
67+
- name: OPTIONAL: The collection name to verify. If this isn't present
68+
then use the collection under test.
69+
- data: The data that should exist in the collection after the
70+
operation has been run.
71+
72+
73+
Use as integration tests
74+
========================
75+
76+
Running these as integration tests will require a running mongod server.
77+
Each of these tests is valid against a standalone mongod, a replica set, and a
78+
sharded system for server version 3.0.0. Many of them will run against 2.4 and
79+
2.6, but some will require conditional code. For instance, $out is not supported
80+
in an aggregation pipeline in server 2.4, so that test must be skipped.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"data": [
3+
{
4+
"_id": 1,
5+
"x": "ping"
6+
}
7+
],
8+
"minServerVersion": "3.4",
9+
"tests": [
10+
{
11+
"description": "Aggregate with collation",
12+
"operation": {
13+
"arguments": {
14+
"collation": {
15+
"locale": "en_US",
16+
"strength": 2
17+
},
18+
"pipeline": [
19+
{
20+
"$match": {
21+
"x": "PING"
22+
}
23+
}
24+
]
25+
},
26+
"name": "aggregate"
27+
},
28+
"outcome": {
29+
"result": [
30+
{
31+
"_id": 1,
32+
"x": "ping"
33+
}
34+
]
35+
}
36+
}
37+
]
38+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
data:
2+
- {_id: 1, x: 'ping'}
3+
minServerVersion: '3.4'
4+
5+
tests:
6+
-
7+
description: "Aggregate with collation"
8+
operation:
9+
name: aggregate
10+
arguments:
11+
pipeline:
12+
- $match:
13+
x: 'PING'
14+
collation: { locale: 'en_US', strength: 2 } # https://docs.mongodb.com/master/reference/collation/#collation-document
15+
outcome:
16+
result:
17+
- {_id: 1, x: 'ping'}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"data": [
3+
{
4+
"_id": 1,
5+
"x": 11
6+
},
7+
{
8+
"_id": 2,
9+
"x": 22
10+
},
11+
{
12+
"_id": 3,
13+
"x": 33
14+
}
15+
],
16+
"minServerVersion": "2.6",
17+
"tests": [
18+
{
19+
"description": "Aggregate with $out",
20+
"operation": {
21+
"arguments": {
22+
"batchSize": 2,
23+
"pipeline": [
24+
{
25+
"$sort": {
26+
"x": 1
27+
}
28+
},
29+
{
30+
"$match": {
31+
"_id": {
32+
"$gt": 1
33+
}
34+
}
35+
},
36+
{
37+
"$out": "other_test_collection"
38+
}
39+
]
40+
},
41+
"name": "aggregate"
42+
},
43+
"outcome": {
44+
"collection": {
45+
"data": [
46+
{
47+
"_id": 2,
48+
"x": 22
49+
},
50+
{
51+
"_id": 3,
52+
"x": 33
53+
}
54+
],
55+
"name": "other_test_collection"
56+
},
57+
"result": [
58+
{
59+
"_id": 2,
60+
"x": 22
61+
},
62+
{
63+
"_id": 3,
64+
"x": 33
65+
}
66+
]
67+
}
68+
}
69+
]
70+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
data:
2+
- {_id: 1, x: 11}
3+
- {_id: 2, x: 22}
4+
- {_id: 3, x: 33}
5+
minServerVersion: '2.6'
6+
7+
tests:
8+
-
9+
description: "Aggregate with $out"
10+
operation:
11+
name: aggregate
12+
arguments:
13+
pipeline:
14+
- $sort: {x: 1}
15+
- $match:
16+
_id: {$gt: 1}
17+
- $out: "other_test_collection"
18+
batchSize: 2
19+
20+
outcome:
21+
result:
22+
- {_id: 2, x: 22}
23+
- {_id: 3, x: 33}
24+
collection:
25+
name: "other_test_collection"
26+
data:
27+
- {_id: 2, x: 22}
28+
- {_id: 3, x: 33}

0 commit comments

Comments
 (0)