Skip to content
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 4 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
]
}
]
}
}
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
description: "modifyCollection-errorResponse"
Copy link
Contributor

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 😢 .

Copy link
Member Author

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 the arguments 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.

Copy link
Contributor

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 our RunCommand API, so would be good to test it. Filed GODRIVER-2587.


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"
Copy link
Member Author

Choose a reason for hiding this comment

The 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 aggregate and findOneAndUpdate are meant to provide some additional test coverage without being exhaustive.

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 source/crud/tests/unified/aggregate-merge-errorResponse.json
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 source/crud/tests/unified/aggregate-merge-errorResponse.yml
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 }
87 changes: 87 additions & 0 deletions source/crud/tests/unified/bulkWrite-errorResponse.json
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
}
}
}
]
}
]
}
Loading