-
Notifications
You must be signed in to change notification settings - Fork 244
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
DRIVERS-2385: expectedError.errorResponse for asserting server-side error doc #1316
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
04bd91e
DRIVERS-2385: expectedError.errorResponse for asserting server-side e…
jmikola 5687e12
Additional tests for expectedError.errorResponse
jmikola 1415116
Note that write errorResponse may need to be skipped in some drivers
jmikola b09899b
Bump changelog date
jmikola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
source/collection-management/tests/modifyCollection-errorResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
{ | ||
"description": "modifyCollection-errorResponse", | ||
"schemaVersion": "1.12", | ||
"createEntities": [ | ||
{ | ||
"client": { | ||
"id": "client0", | ||
"observeEvents": [ | ||
"commandStartedEvent" | ||
] | ||
} | ||
}, | ||
{ | ||
"database": { | ||
"id": "database0", | ||
"client": "client0", | ||
"databaseName": "collMod-tests" | ||
} | ||
}, | ||
{ | ||
"collection": { | ||
"id": "collection0", | ||
"database": "database0", | ||
"collectionName": "test" | ||
} | ||
} | ||
], | ||
"initialData": [ | ||
{ | ||
"collectionName": "test", | ||
"databaseName": "collMod-tests", | ||
"documents": [ | ||
{ | ||
"_id": 1, | ||
"x": 1 | ||
}, | ||
{ | ||
"_id": 2, | ||
"x": 1 | ||
} | ||
] | ||
} | ||
], | ||
"tests": [ | ||
{ | ||
"description": "modifyCollection prepareUnique violations are accessible", | ||
"runOnRequirements": [ | ||
{ | ||
"minServerVersion": "5.2" | ||
} | ||
], | ||
"operations": [ | ||
{ | ||
"name": "createIndex", | ||
"object": "collection0", | ||
"arguments": { | ||
"keys": { | ||
"x": 1 | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "modifyCollection", | ||
"object": "database0", | ||
"arguments": { | ||
"collection": "test", | ||
"index": { | ||
"keyPattern": { | ||
"x": 1 | ||
}, | ||
"prepareUnique": true | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "insertOne", | ||
"object": "collection0", | ||
"arguments": { | ||
"document": { | ||
"_id": 3, | ||
"x": 1 | ||
} | ||
}, | ||
"expectError": { | ||
"errorCode": 11000 | ||
} | ||
}, | ||
{ | ||
"name": "modifyCollection", | ||
"object": "database0", | ||
"arguments": { | ||
"collection": "test", | ||
"index": { | ||
"keyPattern": { | ||
"x": 1 | ||
}, | ||
"unique": true | ||
} | ||
}, | ||
"expectError": { | ||
"isClientError": false, | ||
"errorCode": 359, | ||
"errorResponse": { | ||
"violations": [ | ||
{ | ||
"ids": [ | ||
1, | ||
2 | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
59 changes: 59 additions & 0 deletions
59
source/collection-management/tests/modifyCollection-errorResponse.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
description: "modifyCollection-errorResponse" | ||
|
||
schemaVersion: "1.12" | ||
|
||
createEntities: | ||
- client: | ||
id: &client0 client0 | ||
observeEvents: [ commandStartedEvent ] | ||
- database: | ||
id: &database0 database0 | ||
client: *client0 | ||
databaseName: &database0Name collMod-tests | ||
- collection: | ||
id: &collection0 collection0 | ||
database: *database0 | ||
collectionName: &collection0Name test | ||
|
||
initialData: &initialData | ||
- collectionName: *collection0Name | ||
databaseName: *database0Name | ||
documents: | ||
- { _id: 1, x: 1 } | ||
- { _id: 2, x: 1 } | ||
|
||
tests: | ||
- description: "modifyCollection prepareUnique violations are accessible" | ||
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. This test covers the original impetus for this functionality (see: DRIVERS-2353). The other tests for |
||
runOnRequirements: | ||
- minServerVersion: "5.2" # SERVER-61158 | ||
operations: | ||
- name: createIndex | ||
object: *collection0 | ||
arguments: | ||
keys: { x: 1 } | ||
- name: modifyCollection | ||
object: *database0 | ||
arguments: | ||
collection: *collection0Name | ||
index: | ||
keyPattern: { x: 1 } | ||
prepareUnique: true | ||
- name: insertOne | ||
object: *collection0 | ||
arguments: | ||
document: { _id: 3, x: 1 } | ||
expectError: | ||
errorCode: 11000 # DuplicateKey | ||
- name: modifyCollection | ||
object: *database0 | ||
arguments: | ||
collection: *collection0Name | ||
index: | ||
keyPattern: { x: 1 } | ||
unique: true | ||
expectError: | ||
isClientError: false | ||
errorCode: 359 # CannotConvertIndexToUnique | ||
errorResponse: | ||
violations: | ||
- { ids: [ 1, 2 ] } |
86 changes: 86 additions & 0 deletions
86
source/crud/tests/unified/aggregate-merge-errorResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{ | ||
"description": "aggregate-merge-errorResponse", | ||
"schemaVersion": "1.12", | ||
"createEntities": [ | ||
{ | ||
"client": { | ||
"id": "client0" | ||
} | ||
}, | ||
{ | ||
"database": { | ||
"id": "database0", | ||
"client": "client0", | ||
"databaseName": "crud-tests" | ||
} | ||
}, | ||
{ | ||
"collection": { | ||
"id": "collection0", | ||
"database": "database0", | ||
"collectionName": "test" | ||
} | ||
} | ||
], | ||
"initialData": [ | ||
{ | ||
"collectionName": "test", | ||
"databaseName": "crud-tests", | ||
"documents": [ | ||
{ | ||
"_id": 1, | ||
"x": 1 | ||
}, | ||
{ | ||
"_id": 2, | ||
"x": 1 | ||
} | ||
] | ||
} | ||
], | ||
"tests": [ | ||
{ | ||
"description": "aggregate $merge DuplicateKey error is accessible", | ||
"runOnRequirements": [ | ||
{ | ||
"minServerVersion": "5.1" | ||
} | ||
], | ||
"operations": [ | ||
{ | ||
"name": "aggregate", | ||
"object": "database0", | ||
"arguments": { | ||
"pipeline": [ | ||
{ | ||
"$documents": [ | ||
{ | ||
"_id": 2, | ||
"x": 1 | ||
} | ||
] | ||
}, | ||
{ | ||
"$merge": { | ||
"into": "test", | ||
"whenMatched": "fail" | ||
} | ||
} | ||
] | ||
}, | ||
"expectError": { | ||
"errorCode": 11000, | ||
"errorResponse": { | ||
"keyPattern": { | ||
"_id": 1 | ||
}, | ||
"keyValue": { | ||
"_id": 2 | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
39 changes: 39 additions & 0 deletions
39
source/crud/tests/unified/aggregate-merge-errorResponse.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
description: "aggregate-merge-errorResponse" | ||
|
||
schemaVersion: "1.12" | ||
|
||
createEntities: | ||
- client: | ||
id: &client0 client0 | ||
- database: | ||
id: &database0 database0 | ||
client: *client0 | ||
databaseName: &database0Name crud-tests | ||
- collection: | ||
id: &collection0 collection0 | ||
database: *database0 | ||
collectionName: &collection0Name test | ||
|
||
initialData: &initialData | ||
- collectionName: *collection0Name | ||
databaseName: *database0Name | ||
documents: | ||
- { _id: 1, x: 1 } | ||
- { _id: 2, x: 1 } | ||
|
||
tests: | ||
- description: "aggregate $merge DuplicateKey error is accessible" | ||
runOnRequirements: | ||
- minServerVersion: "5.1" # SERVER-59097 | ||
operations: | ||
- name: aggregate | ||
object: *database0 | ||
arguments: | ||
pipeline: | ||
- { $documents: [ { _id: 2, x: 1 } ] } | ||
- { $merge: { into: *collection0Name, whenMatched: "fail" } } | ||
expectError: | ||
errorCode: 11000 # DuplicateKey | ||
errorResponse: | ||
keyPattern: { _id: 1 } | ||
keyValue: { _id: 2 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{ | ||
"description": "bulkWrite-errorResponse", | ||
"schemaVersion": "1.12", | ||
"createEntities": [ | ||
{ | ||
"client": { | ||
"id": "client0" | ||
} | ||
}, | ||
{ | ||
"database": { | ||
"id": "database0", | ||
"client": "client0", | ||
"databaseName": "crud-tests" | ||
} | ||
}, | ||
{ | ||
"collection": { | ||
"id": "collection0", | ||
"database": "database0", | ||
"collectionName": "test" | ||
} | ||
} | ||
], | ||
"tests": [ | ||
{ | ||
"description": "bulkWrite operations support errorResponse assertions", | ||
"runOnRequirements": [ | ||
{ | ||
"minServerVersion": "4.0.0", | ||
"topologies": [ | ||
"single", | ||
"replicaset" | ||
] | ||
}, | ||
{ | ||
"minServerVersion": "4.2.0", | ||
"topologies": [ | ||
"sharded" | ||
] | ||
} | ||
], | ||
"operations": [ | ||
{ | ||
"name": "failPoint", | ||
"object": "testRunner", | ||
"arguments": { | ||
"client": "client0", | ||
"failPoint": { | ||
"configureFailPoint": "failCommand", | ||
"mode": { | ||
"times": 1 | ||
}, | ||
"data": { | ||
"failCommands": [ | ||
"insert" | ||
], | ||
"errorCode": 8 | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "bulkWrite", | ||
"object": "collection0", | ||
"arguments": { | ||
"requests": [ | ||
{ | ||
"insertOne": { | ||
"document": { | ||
"_id": 1 | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"expectError": { | ||
"errorCode": 8, | ||
"errorResponse": { | ||
"code": 8 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Go driver does not have a
modifyCollection
helper, so I can't run this test 😢 .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the benefit of test coverage, have you considered implementing the operation via
runCommand
in your test suite? PHP has a helper for it but we don't actually model all of the possible parameters, so it should be quite trivial to just build a command document from thearguments
in the test operation if you wanted.Maybe not so relevant for this case, since the purpose of the test is to ensure a helper provides appropriate error access, but it could allow you to run some other tests that happen to use
modifyCollection
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah an interesting point; I imagine users are already running
collMod
through ourRunCommand
API, so would be good to test it. Filed GODRIVER-2587.