-
Notifications
You must be signed in to change notification settings - Fork 244
Add uri options tests #414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4e0048b
f9fd27f
68f70a3
1e29a9a
cc6e590
23af0c4
8341942
2be7e48
27ffa77
c385b20
371041e
bfeb58e
af548c1
3fa72d2
9f7f05c
3690a14
44bf061
b28ee9e
917c3b3
42b555d
55824c9
931f684
0d42dbd
d91db3b
5a508de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
======================= | ||
URI Options Tests | ||
======================= | ||
|
||
The YAML and JSON files in this directory tree are platform-independent tests | ||
that drivers can use to prove their conformance to the URI Options spec. | ||
|
||
These tests use the same format as the Connection String spec tests. | ||
|
||
Version | ||
------- | ||
|
||
Files in the "specifications" repository have no version scheme. They are not | ||
tied to a MongoDB server version. | ||
|
||
Format | ||
------ | ||
|
||
Each YAML file contains an object with a single ``tests`` key. This key is an | ||
array of test case objects, each of which have the following keys: | ||
|
||
- ``description``: A string describing the test. | ||
- ``uri``: A string containing the URI to be parsed. | ||
- ``valid``: A boolean indicating if the URI should be considered valid. | ||
This will always be true, as the Connection String spec tests the validity of the structure, but | ||
it's still included to make it easier to reuse the connection string spec test runners that | ||
drivers already have. | ||
- ``warning``: A boolean indicating whether URI parsing should emit a warning. | ||
- ``hosts``: Included for compatibility with the Connection String spec tests. This will always be ``~``. | ||
- ``auth``: Included for compatibility with the Connection String spec tests. This will always be ``~``. | ||
- ``options``: An object containing key/value pairs for each parsed query string | ||
option. | ||
|
||
If a test case includes a null value for one of these keys (e.g. ``auth: ~``, | ||
``hosts: ~``), no assertion is necessary. This both simplifies parsing of the | ||
test files (keys should always exist) and allows flexibility for drivers that | ||
might substitute default values *during* parsing (e.g. omitted ``hosts`` could be | ||
parsed as ``["localhost"]``). | ||
|
||
The ``valid`` and ``warning`` fields are boolean in order to keep the tests | ||
flexible. We are not concerned with asserting the format of specific error or | ||
warnings messages strings. | ||
|
||
Use as unit tests | ||
================= | ||
|
||
Testing whether a URI is valid or not requires testing whether URI parsing (or | ||
MongoClient construction) causes a warning due to a URI option being invalid and asserting that the | ||
options parsed from the URI match those listed in the ``options`` field. | ||
|
||
Note that there are tests for each of the options marked as optional; drivers will need to implement | ||
logic to skip over the optional tests that they don’t implement. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"description": "Valid auth options are parsed correctly", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this test. It's saying that you should be able to specify all the auth options, but if there's no user name, auth should be disabled (but the auth properties should still be accessible)? Java driver doesn't support this, as the ConnectionString returns a fully formed MongoCredential, not individual properties? Would it go against the purpose of this test to add a username to the URI? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hadn't considered that drivers might parse all options into a single object at once; I can add a username to this test. |
||
"uri": "mongodb://foo:bar@example.com/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:true&authSource=$external", | ||
"valid": true, | ||
"warning": false, | ||
"hosts": null, | ||
"auth": null, | ||
"options": { | ||
"authMechanism": "GSSAPI", | ||
"authMechanismProperties": { | ||
"SERVICE_NAME": "other", | ||
"CANONICALIZE_HOST_NAME": true | ||
}, | ||
"authSource": "$external" | ||
} | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
tests: | ||
- | ||
description: "Valid auth options are parsed correctly" | ||
uri: "mongodb://foo:bar@example.com/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:true&authSource=$external" | ||
valid: true | ||
warning: false | ||
hosts: ~ | ||
auth: ~ | ||
options: | ||
authMechanism: "GSSAPI" | ||
authMechanismProperties: | ||
SERVICE_NAME: "other" | ||
CANONICALIZE_HOST_NAME: true | ||
authSource: "$external" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# This file exists solely for the purpose of facilitating drivers which check for the existence of files specified in the URI options at parse time. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# This file exists solely for the purpose of facilitating drivers which check for the existence of files specified in the URI options at parse time. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# This file exists solely for the purpose of facilitating drivers which check for the existence of files specified in the URI options at parse time. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"description": "Valid compression options are parsed correctly", | ||
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=9", | ||
"valid": true, | ||
"warning": false, | ||
"hosts": null, | ||
"auth": null, | ||
"options": { | ||
"compressors": [ | ||
"zlib" | ||
], | ||
"zlibCompressionLevel": 9 | ||
} | ||
}, | ||
{ | ||
"description": "Multiple compressors are parsed correctly", | ||
"uri": "mongodb://example.com/?compressors=snappy,zlib", | ||
"valid": true, | ||
"warning": true, | ||
"hosts": null, | ||
"auth": null, | ||
"options": { | ||
"compressors": [ | ||
"snappy", | ||
"zlib" | ||
] | ||
} | ||
}, | ||
{ | ||
"description": "Non-numeric zlibCompressionLevel causes a warning", | ||
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=invalid", | ||
"valid": true, | ||
"warning": true, | ||
"hosts": null, | ||
"auth": null, | ||
"options": {} | ||
}, | ||
{ | ||
"description": "Too low zlibCompressionLevel causes a warning", | ||
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=-2", | ||
"valid": true, | ||
"warning": true, | ||
"hosts": null, | ||
"auth": null, | ||
"options": {} | ||
}, | ||
{ | ||
"description": "Too high zlibCompressionLevel causes a warning", | ||
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=10", | ||
"valid": true, | ||
"warning": true, | ||
"hosts": null, | ||
"auth": null, | ||
"options": {} | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
tests: | ||
- | ||
description: "Valid compression options are parsed correctly" | ||
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=9" | ||
valid: true | ||
warning: false | ||
hosts: ~ | ||
auth: ~ | ||
options: | ||
compressors: | ||
- "zlib" | ||
zlibCompressionLevel: 9 | ||
- | ||
description: "Multiple compressors are parsed correctly" | ||
uri: "mongodb://example.com/?compressors=snappy,zlib" | ||
valid: true | ||
warning: true | ||
hosts: ~ | ||
auth: ~ | ||
options: | ||
compressors: | ||
- "snappy" | ||
- "zlib" | ||
- | ||
description: "Non-numeric zlibCompressionLevel causes a warning" | ||
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=invalid" | ||
valid: true | ||
warning: true | ||
hosts: ~ | ||
auth: ~ | ||
options: {} | ||
- | ||
description: "Too low zlibCompressionLevel causes a warning" | ||
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=-2" | ||
valid: true | ||
warning: true | ||
hosts: ~ | ||
auth: ~ | ||
options: {} | ||
- | ||
description: "Too high zlibCompressionLevel causes a warning" | ||
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=10" | ||
valid: true | ||
warning: true | ||
hosts: ~ | ||
auth: ~ | ||
options: {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"description": "Valid read and write concern are parsed correctly", | ||
"uri": "mongodb://example.com/?readConcernLevel=majority&w=5&wTimeoutMS=30000&journal=false", | ||
"valid": true, | ||
"warning": false, | ||
"hosts": null, | ||
"auth": null, | ||
"options": { | ||
"readConcernLevel": "majority", | ||
"w": 5, | ||
"wTimeoutMS": 30000, | ||
"journal": false | ||
} | ||
}, | ||
{ | ||
"description": "Arbitrary string readConcernLevel does not cause a warning", | ||
"uri": "mongodb://example.com/?readConcernLevel=arbitraryButStillValid", | ||
"valid": true, | ||
"warning": false, | ||
"hosts": null, | ||
"auth": null, | ||
"options": { | ||
"readConcernLevel": "arbitraryButStillValid" | ||
} | ||
}, | ||
{ | ||
"description": "Arbitrary string w doesn't cause a warning", | ||
"uri": "mongodb://example.com/?w=arbitraryButStillValid", | ||
"valid": true, | ||
"warning": false, | ||
"hosts": null, | ||
"auth": null, | ||
"options": { | ||
"w": "arbitraryButStillValid" | ||
} | ||
}, | ||
{ | ||
"description": "Too low w causes a warning", | ||
"uri": "mongodb://example.com/?w=-2", | ||
"valid": true, | ||
"warning": true, | ||
"hosts": null, | ||
"auth": null, | ||
"options": {} | ||
}, | ||
{ | ||
"description": "Non-numeric wTimeoutMS causes a warning", | ||
"uri": "mongodb://example.com/?wTimeoutMS=invalid", | ||
"valid": true, | ||
"warning": true, | ||
"hosts": null, | ||
"auth": null, | ||
"options": {} | ||
}, | ||
{ | ||
"description": "Too low wTimeoutMS causes a warning", | ||
"uri": "mongodb://example.com/?wTimeoutMS=-2", | ||
"valid": true, | ||
"warning": true, | ||
"hosts": null, | ||
"auth": null, | ||
"options": {} | ||
}, | ||
{ | ||
"description": "Invalid journal causes a warning", | ||
"uri": "mongodb://example.com/?journal=invalid", | ||
"valid": true, | ||
"warning": true, | ||
"hosts": null, | ||
"auth": null, | ||
"options": {} | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
tests: | ||
- | ||
description: "Valid read and write concern are parsed correctly" | ||
uri: "mongodb://example.com/?readConcernLevel=majority&w=5&wTimeoutMS=30000&journal=false" | ||
valid: true | ||
warning: false | ||
hosts: ~ | ||
auth: ~ | ||
options: | ||
readConcernLevel: "majority" | ||
w: 5 | ||
wTimeoutMS: 30000 | ||
journal: false | ||
- | ||
description: "Arbitrary string readConcernLevel does not cause a warning" | ||
uri: "mongodb://example.com/?readConcernLevel=arbitraryButStillValid" | ||
valid: true | ||
warning: false | ||
hosts: ~ | ||
auth: ~ | ||
options: | ||
readConcernLevel: "arbitraryButStillValid" | ||
- | ||
description: "Arbitrary string w doesn't cause a warning" | ||
uri: "mongodb://example.com/?w=arbitraryButStillValid" | ||
valid: true | ||
warning: false | ||
hosts: ~ | ||
auth: ~ | ||
options: | ||
w: "arbitraryButStillValid" | ||
- | ||
description: "Non-numeric wTimeoutMS causes a warning" | ||
uri: "mongodb://example.com/?wTimeoutMS=invalid" | ||
valid: true | ||
warning: true | ||
hosts: ~ | ||
auth: ~ | ||
options: {} | ||
- | ||
description: "Too low wTimeoutMS causes a warning" | ||
uri: "mongodb://example.com/?wTimeoutMS=-2" | ||
valid: true | ||
warning: true | ||
hosts: ~ | ||
auth: ~ | ||
options: {} | ||
- | ||
description: "Invalid journal causes a warning" | ||
uri: "mongodb://example.com/?journal=invalid" | ||
valid: true | ||
warning: true | ||
hosts: ~ | ||
auth: ~ | ||
options: {} |
Uh oh!
There was an error while loading. Please reload this page.