Skip to content

Commit 8984bab

Browse files
committed
Pass all non-warning-related URI options specification tests
JAVA-3066
1 parent c45d0af commit 8984bab

11 files changed

+709
-7
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
=======================
2+
URI Options Tests
3+
=======================
4+
5+
The YAML and JSON files in this directory tree are platform-independent tests
6+
that drivers can use to prove their conformance to the URI Options spec.
7+
8+
These tests use the same format as the Connection String spec tests.
9+
10+
Version
11+
-------
12+
13+
Files in the "specifications" repository have no version scheme. They are not
14+
tied to a MongoDB server version.
15+
16+
Format
17+
------
18+
19+
Each YAML file contains an object with a single ``tests`` key. This key is an
20+
array of test case objects, each of which have the following keys:
21+
22+
- ``description``: A string describing the test.
23+
- ``uri``: A string containing the URI to be parsed.
24+
- ``valid``: A boolean indicating if the URI should be considered valid.
25+
This will always be true, as the Connection String spec tests the validity of the structure, but
26+
it's still included to make it easier to reuse the connection string spec test runners that
27+
drivers already have.
28+
- ``warning``: A boolean indicating whether URI parsing should emit a warning.
29+
- ``hosts``: Included for compatibility with the Connection String spec tests. This will always be ``~``.
30+
- ``auth``: Included for compatibility with the Connection String spec tests. This will always be ``~``.
31+
- ``options``: An object containing key/value pairs for each parsed query string
32+
option.
33+
34+
If a test case includes a null value for one of these keys (e.g. ``auth: ~``,
35+
``hosts: ~``), no assertion is necessary. This both simplifies parsing of the
36+
test files (keys should always exist) and allows flexibility for drivers that
37+
might substitute default values *during* parsing (e.g. omitted ``hosts`` could be
38+
parsed as ``["localhost"]``).
39+
40+
The ``valid`` and ``warning`` fields are boolean in order to keep the tests
41+
flexible. We are not concerned with asserting the format of specific error or
42+
warnings messages strings.
43+
44+
Use as unit tests
45+
=================
46+
47+
Testing whether a URI is valid or not requires testing whether URI parsing (or
48+
MongoClient construction) causes a warning due to a URI option being invalid and asserting that the
49+
options parsed from the URI match those listed in the ``options`` field.
50+
51+
Note that there are tests for each of the options marked as optional; drivers will need to implement
52+
logic to skip over the optional tests that they don’t implement.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"tests": [
3+
{
4+
"description": "Valid auth options are parsed correctly",
5+
"uri": "mongodb://foo:[email protected]/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:true&authSource=$external",
6+
"valid": true,
7+
"warning": false,
8+
"hosts": null,
9+
"auth": null,
10+
"options": {
11+
"authMechanism": "GSSAPI",
12+
"authMechanismProperties": {
13+
"SERVICE_NAME": "other",
14+
"CANONICALIZE_HOST_NAME": true
15+
},
16+
"authSource": "$external"
17+
}
18+
}
19+
]
20+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"tests": [
3+
{
4+
"description": "Valid compression options are parsed correctly",
5+
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=9",
6+
"valid": true,
7+
"warning": false,
8+
"hosts": null,
9+
"auth": null,
10+
"options": {
11+
"compressors": [
12+
"zlib"
13+
],
14+
"zlibCompressionLevel": 9
15+
}
16+
},
17+
{
18+
"description": "Multiple compressors are parsed correctly",
19+
"uri": "mongodb://example.com/?compressors=snappy,zlib",
20+
"valid": true,
21+
"warning": true,
22+
"hosts": null,
23+
"auth": null,
24+
"options": {
25+
"compressors": [
26+
"snappy",
27+
"zlib"
28+
]
29+
}
30+
},
31+
{
32+
"description": "Non-numeric zlibCompressionLevel causes a warning",
33+
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=invalid",
34+
"valid": true,
35+
"warning": true,
36+
"hosts": null,
37+
"auth": null,
38+
"options": {}
39+
},
40+
{
41+
"description": "Too low zlibCompressionLevel causes a warning",
42+
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=-2",
43+
"valid": true,
44+
"warning": true,
45+
"hosts": null,
46+
"auth": null,
47+
"options": {}
48+
},
49+
{
50+
"description": "Too high zlibCompressionLevel causes a warning",
51+
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=10",
52+
"valid": true,
53+
"warning": true,
54+
"hosts": null,
55+
"auth": null,
56+
"options": {}
57+
}
58+
]
59+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"tests": [
3+
{
4+
"description": "Valid read and write concern are parsed correctly",
5+
"uri": "mongodb://example.com/?readConcernLevel=majority&w=5&wTimeoutMS=30000&journal=false",
6+
"valid": true,
7+
"warning": false,
8+
"hosts": null,
9+
"auth": null,
10+
"options": {
11+
"readConcernLevel": "majority",
12+
"w": 5,
13+
"wTimeoutMS": 30000,
14+
"journal": false
15+
}
16+
},
17+
{
18+
"description": "Arbitrary string readConcernLevel does not cause a warning",
19+
"uri": "mongodb://example.com/?readConcernLevel=arbitraryButStillValid",
20+
"valid": true,
21+
"warning": false,
22+
"hosts": null,
23+
"auth": null,
24+
"options": {
25+
"readConcernLevel": "arbitraryButStillValid"
26+
}
27+
},
28+
{
29+
"description": "Arbitrary string w doesn't cause a warning",
30+
"uri": "mongodb://example.com/?w=arbitraryButStillValid",
31+
"valid": true,
32+
"warning": false,
33+
"hosts": null,
34+
"auth": null,
35+
"options": {
36+
"w": "arbitraryButStillValid"
37+
}
38+
},
39+
{
40+
"description": "Too low w causes a warning",
41+
"uri": "mongodb://example.com/?w=-2",
42+
"valid": true,
43+
"warning": true,
44+
"hosts": null,
45+
"auth": null,
46+
"options": {}
47+
},
48+
{
49+
"description": "Non-numeric wTimeoutMS causes a warning",
50+
"uri": "mongodb://example.com/?wTimeoutMS=invalid",
51+
"valid": true,
52+
"warning": true,
53+
"hosts": null,
54+
"auth": null,
55+
"options": {}
56+
},
57+
{
58+
"description": "Too low wTimeoutMS causes a warning",
59+
"uri": "mongodb://example.com/?wTimeoutMS=-2",
60+
"valid": true,
61+
"warning": true,
62+
"hosts": null,
63+
"auth": null,
64+
"options": {}
65+
},
66+
{
67+
"description": "Invalid journal causes a warning",
68+
"uri": "mongodb://example.com/?journal=invalid",
69+
"valid": true,
70+
"warning": true,
71+
"hosts": null,
72+
"auth": null,
73+
"options": {}
74+
}
75+
]
76+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"tests": [
3+
{
4+
"description": "Valid connection and timeout options are parsed correctly",
5+
"uri": "mongodb://example.com/?appname=URI-OPTIONS-SPEC-TEST&connectTimeoutMS=20000&heartbeatFrequencyMS=5000&localThresholdMS=3000&maxIdleTimeMS=50000&replicaSet=uri-options-spec&retryWrites=true&serverSelectionTimeoutMS=15000&socketTimeoutMS=7500",
6+
"valid": true,
7+
"warning": false,
8+
"hosts": null,
9+
"auth": null,
10+
"options": {
11+
"appname": "URI-OPTIONS-SPEC-TEST",
12+
"connectTimeoutMS": 20000,
13+
"heartbeatFrequencyMS": 5000,
14+
"localThresholdMS": 3000,
15+
"maxIdleTimeMS": 50000,
16+
"replicaSet": "uri-options-spec",
17+
"retryWrites": true,
18+
"serverSelectionTimeoutMS": 15000,
19+
"socketTimeoutMS": 7500
20+
}
21+
},
22+
{
23+
"description": "Non-numeric connectTimeoutMS causes a warning",
24+
"uri": "mongodb://example.com/?connectTimeoutMS=invalid",
25+
"valid": true,
26+
"warning": true,
27+
"hosts": null,
28+
"auth": null,
29+
"options": {}
30+
},
31+
{
32+
"description": "Too low connectTimeoutMS causes a warning",
33+
"uri": "mongodb://example.com/?connectTimeoutMS=-2",
34+
"valid": true,
35+
"warning": true,
36+
"hosts": null,
37+
"auth": null,
38+
"options": {}
39+
},
40+
{
41+
"description": "Non-numeric heartbeatFrequencyMS causes a warning",
42+
"uri": "mongodb://example.com/?heartbeatFrequencyMS=invalid",
43+
"valid": true,
44+
"warning": true,
45+
"hosts": null,
46+
"auth": null,
47+
"options": {}
48+
},
49+
{
50+
"description": "Too low heartbeatFrequencyMS causes a warning",
51+
"uri": "mongodb://example.com/?heartbeatFrequencyMS=-2",
52+
"valid": true,
53+
"warning": true,
54+
"hosts": null,
55+
"auth": null,
56+
"options": {}
57+
},
58+
{
59+
"description": "Non-numeric localThresholdMS causes a warning",
60+
"uri": "mongodb://example.com/?localThresholdMS=invalid",
61+
"valid": true,
62+
"warning": true,
63+
"hosts": null,
64+
"auth": null,
65+
"options": {}
66+
},
67+
{
68+
"description": "Too low localThresholdMS causes a warning",
69+
"uri": "mongodb://example.com/?localThresholdMS=-2",
70+
"valid": true,
71+
"warning": true,
72+
"hosts": null,
73+
"auth": null,
74+
"options": {}
75+
},
76+
{
77+
"description": "Invalid retryWrites causes a warning",
78+
"uri": "mongodb://example.com/?retryWrites=invalid",
79+
"valid": true,
80+
"warning": true,
81+
"hosts": null,
82+
"auth": null,
83+
"options": {}
84+
},
85+
{
86+
"description": "Non-numeric serverSelectionTimeoutMS causes a warning",
87+
"uri": "mongodb://example.com/?serverSelectionTimeoutMS=invalid",
88+
"valid": true,
89+
"warning": true,
90+
"hosts": null,
91+
"auth": null,
92+
"options": {}
93+
},
94+
{
95+
"description": "Too low serverSelectionTimeoutMS causes a warning",
96+
"uri": "mongodb://example.com/?serverSelectionTimeoutMS=-2",
97+
"valid": true,
98+
"warning": true,
99+
"hosts": null,
100+
"auth": null,
101+
"options": {}
102+
},
103+
{
104+
"description": "Non-numeric socketTimeoutMS causes a warning",
105+
"uri": "mongodb://example.com/?socketTimeoutMS=invalid",
106+
"valid": true,
107+
"warning": true,
108+
"hosts": null,
109+
"auth": null,
110+
"options": {}
111+
},
112+
{
113+
"description": "Too low socketTimeoutMS causes a warning",
114+
"uri": "mongodb://example.com/?socketTimeoutMS=-2",
115+
"valid": true,
116+
"warning": true,
117+
"hosts": null,
118+
"auth": null,
119+
"options": {}
120+
}
121+
]
122+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"tests": [
3+
{
4+
"description": "Valid connection pool options are parsed correctly",
5+
"uri": "mongodb://example.com/?maxIdleTimeMS=50000",
6+
"valid": true,
7+
"warning": false,
8+
"hosts": null,
9+
"auth": null,
10+
"options": {
11+
"maxIdleTimeMS": 50000
12+
}
13+
},
14+
{
15+
"description": "Non-numeric maxIdleTimeMS causes a warning",
16+
"uri": "mongodb://example.com/?maxIdleTimeMS=invalid",
17+
"valid": true,
18+
"warning": true,
19+
"hosts": null,
20+
"auth": null,
21+
"options": {}
22+
},
23+
{
24+
"description": "Too low maxIdleTimeMS causes a warning",
25+
"uri": "mongodb://example.com/?maxIdleTimeMS=-2",
26+
"valid": true,
27+
"warning": true,
28+
"hosts": null,
29+
"auth": null,
30+
"options": {}
31+
}
32+
]
33+
}

0 commit comments

Comments
 (0)