Skip to content

Commit 1991c44

Browse files
committed
CSHARP-1897: Resync CRUD spec tests.
1 parent 7c55afa commit 1991c44

Some content is hidden

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

51 files changed

+3782
-2754
lines changed

tests/MongoDB.Driver.Tests/MongoDB.Driver.Tests.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,12 @@
320320
<EmbeddedResource Include="Specifications\crud\tests\write\findOneAndReplace-upsert.json" />
321321
<EmbeddedResource Include="Specifications\crud\tests\write\findOneAndUpdate-collation.json" />
322322
<EmbeddedResource Include="Specifications\crud\tests\write\replaceOne-collation.json" />
323-
<EmbeddedResource Include="Specifications\crud\tests\write\replaceOne-upsert.json" />
324323
<EmbeddedResource Include="Specifications\crud\tests\write\updateMany-collation.json" />
325324
<EmbeddedResource Include="Specifications\crud\tests\write\updateOne-collation.json" />
325+
<EmbeddedResource Include="Specifications\crud\tests\write\findOneAndReplace-upsert_pre_2.6.json" />
326+
<EmbeddedResource Include="Specifications\crud\tests\write\replaceOne-pre_2.6.json" />
327+
<EmbeddedResource Include="Specifications\crud\tests\write\updateMany-pre_2.6.json" />
328+
<EmbeddedResource Include="Specifications\crud\tests\write\updateOne-pre_2.6.json" />
326329
<None Include="testcert.pfx">
327330
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
328331
</None>

tests/MongoDB.Driver.Tests/Specifications/crud/FindOneAndReplaceTest.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ protected override BsonDocument ConvertExpectedResult(BsonValue expectedResult)
6262
{
6363
if (expectedResult.IsBsonNull)
6464
{
65-
if (ClusterDescription.Servers[0].Version < new SemanticVersion(3, 0, 0) && _options.IsUpsert)
66-
{
67-
return new BsonDocument();
68-
}
6965
return null;
7066
}
7167

tests/MongoDB.Driver.Tests/Specifications/crud/FindOneAndUpdateTest.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ protected override BsonDocument ConvertExpectedResult(BsonValue expectedResult)
6161
{
6262
if (expectedResult.IsBsonNull)
6363
{
64-
if (ClusterDescription.Servers[0].Version < new SemanticVersion(3, 0, 0) && _options.IsUpsert)
65-
{
66-
return new BsonDocument();
67-
}
6864
return null;
6965
}
7066

tests/MongoDB.Driver.Tests/Specifications/crud/tests/README.rst

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,87 @@ CRUD Tests
33
==========
44

55
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-
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+
implementation.
1514

1615
Converting to JSON
1716
==================
1817

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>`_::
18+
The tests are written in YAML because it is easier for humans to write and read,
19+
and because YAML includes a standard comment format. A JSONified version of each
20+
YAML file is included in this repository. Whenever a YAML file is modified, the
21+
corresponding JSON file should be regenerated. One method to convert to JSON is
22+
using `yamljs <https://www.npmjs.com/package/yamljs>`_::
2623

2724
npm install -g yamljs
28-
yaml2json -s -p -r .
29-
25+
yaml2json -s -p -r .
3026

3127
Version
3228
=======
3329

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.
30+
Files in the "specifications" repository have no version scheme. They are not
31+
tied to a MongoDB server version, and it is our intention that each
32+
specification moves from "draft" to "final" with no further revisions; it is
33+
superseded by a future spec, not revised.
3834

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.
35+
However, implementers must have stable sets of tests to target. As test files
36+
evolve they will occasionally be tagged like "crud-tests-YYYY-MM-DD", until the
37+
spec is final.
4238

4339
Format
4440
======
4541

4642
Each YAML file has the following keys:
4743

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.
44+
- ``data``: The data that should exist in the collection under test before each
45+
test run.
46+
47+
- ``minServerVersion`` (optional): The minimum server version (inclusive)
48+
required to successfully run the test. If this field is not present, it should
49+
be assumed that there is no lower bound on the required server version.
50+
51+
- ``maxServerVersion`` (optional): The maximum server version (exclusive)
52+
against which this test can run successfully. If this field is not present,
53+
it should be assumed that there is no upper bound on the required server
54+
version.
55+
56+
- ``tests``: An array of tests that are to be run independently of each other.
57+
Each test will have some or all of the following fields:
58+
59+
- ``description``: The name of the test.
60+
61+
- ``operation``: Document describing the operation to be executed. This will
62+
have the following fields:
63+
64+
- ``name``: The name of the operation as defined in the specification.
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+
- ``result``: The return value from the operation.
73+
74+
- ``collection``:
75+
76+
- ``name`` (optional): The name of the collection to verify. If this
77+
isn't present then use the collection under test.
7178

79+
- ``data``: The data that should exist in the collection after the
80+
operation has been run.
7281

7382
Use as integration tests
7483
========================
7584

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.
85+
Running these as integration tests will require a running mongod server. Each of
86+
these tests is valid against a standalone mongod, a replica set, and a sharded
87+
system for server version 3.0.0. Many of them will run against 2.4 and 2.6, but
88+
some will require conditional code. For instance, ``$out`` is not supported in
89+
an aggregation pipeline in server 2.4, so that test must be skipped.
Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
{
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-
]
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+
"name": "aggregate",
14+
"arguments": {
15+
"pipeline": [
16+
{
17+
"$match": {
18+
"x": "PING"
19+
}
3520
}
21+
],
22+
"collation": {
23+
"locale": "en_US",
24+
"strength": 2
25+
}
3626
}
37-
]
38-
}
27+
},
28+
"outcome": {
29+
"result": [
30+
{
31+
"_id": 1,
32+
"x": "ping"
33+
}
34+
]
35+
}
36+
}
37+
]
38+
}
Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
11
{
2-
"data": [
3-
{
4-
"_id": 1,
5-
"x": 11
6-
},
7-
{
8-
"_id": 2,
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+
"name": "aggregate",
22+
"arguments": {
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+
"batchSize": 2
41+
}
42+
},
43+
"outcome": {
44+
"result": [
45+
{
46+
"_id": 2,
947
"x": 22
10-
},
11-
{
12-
"_id": 3,
48+
},
49+
{
50+
"_id": 3,
1351
"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-
]
52+
}
53+
],
54+
"collection": {
55+
"name": "other_test_collection",
56+
"data": [
57+
{
58+
"_id": 2,
59+
"x": 22
60+
},
61+
{
62+
"_id": 3,
63+
"x": 33
6764
}
65+
]
6866
}
69-
]
70-
}
67+
}
68+
}
69+
]
70+
}

0 commit comments

Comments
 (0)