Skip to content

Commit 081578a

Browse files
authored
DRIVERS-2385: expectedError.errorResponse for asserting server-side error doc (#1316)
Adds basic tests for expectedError.errorResponse under the unified test format, which are derived from the operation-failure tests in valid-fail. Also adds tests for write operations (i.e. insert, update, delete, and bulkWrite), which may be problematic for some drivers that use special exceptions such as BulkWriteException, which may not provide direct access to a single response. Note that tests should avoid using errorResponse assertions for such operations and permit drivers to skip those tests as needed.
1 parent e081028 commit 081578a

21 files changed

+1815
-2
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"description": "modifyCollection-errorResponse",
3+
"schemaVersion": "1.12",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"observeEvents": [
9+
"commandStartedEvent"
10+
]
11+
}
12+
},
13+
{
14+
"database": {
15+
"id": "database0",
16+
"client": "client0",
17+
"databaseName": "collMod-tests"
18+
}
19+
},
20+
{
21+
"collection": {
22+
"id": "collection0",
23+
"database": "database0",
24+
"collectionName": "test"
25+
}
26+
}
27+
],
28+
"initialData": [
29+
{
30+
"collectionName": "test",
31+
"databaseName": "collMod-tests",
32+
"documents": [
33+
{
34+
"_id": 1,
35+
"x": 1
36+
},
37+
{
38+
"_id": 2,
39+
"x": 1
40+
}
41+
]
42+
}
43+
],
44+
"tests": [
45+
{
46+
"description": "modifyCollection prepareUnique violations are accessible",
47+
"runOnRequirements": [
48+
{
49+
"minServerVersion": "5.2"
50+
}
51+
],
52+
"operations": [
53+
{
54+
"name": "createIndex",
55+
"object": "collection0",
56+
"arguments": {
57+
"keys": {
58+
"x": 1
59+
}
60+
}
61+
},
62+
{
63+
"name": "modifyCollection",
64+
"object": "database0",
65+
"arguments": {
66+
"collection": "test",
67+
"index": {
68+
"keyPattern": {
69+
"x": 1
70+
},
71+
"prepareUnique": true
72+
}
73+
}
74+
},
75+
{
76+
"name": "insertOne",
77+
"object": "collection0",
78+
"arguments": {
79+
"document": {
80+
"_id": 3,
81+
"x": 1
82+
}
83+
},
84+
"expectError": {
85+
"errorCode": 11000
86+
}
87+
},
88+
{
89+
"name": "modifyCollection",
90+
"object": "database0",
91+
"arguments": {
92+
"collection": "test",
93+
"index": {
94+
"keyPattern": {
95+
"x": 1
96+
},
97+
"unique": true
98+
}
99+
},
100+
"expectError": {
101+
"isClientError": false,
102+
"errorCode": 359,
103+
"errorResponse": {
104+
"violations": [
105+
{
106+
"ids": [
107+
1,
108+
2
109+
]
110+
}
111+
]
112+
}
113+
}
114+
}
115+
]
116+
}
117+
]
118+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
description: "modifyCollection-errorResponse"
2+
3+
schemaVersion: "1.12"
4+
5+
createEntities:
6+
- client:
7+
id: &client0 client0
8+
observeEvents: [ commandStartedEvent ]
9+
- database:
10+
id: &database0 database0
11+
client: *client0
12+
databaseName: &database0Name collMod-tests
13+
- collection:
14+
id: &collection0 collection0
15+
database: *database0
16+
collectionName: &collection0Name test
17+
18+
initialData: &initialData
19+
- collectionName: *collection0Name
20+
databaseName: *database0Name
21+
documents:
22+
- { _id: 1, x: 1 }
23+
- { _id: 2, x: 1 }
24+
25+
tests:
26+
- description: "modifyCollection prepareUnique violations are accessible"
27+
runOnRequirements:
28+
- minServerVersion: "5.2" # SERVER-61158
29+
operations:
30+
- name: createIndex
31+
object: *collection0
32+
arguments:
33+
keys: { x: 1 }
34+
- name: modifyCollection
35+
object: *database0
36+
arguments:
37+
collection: *collection0Name
38+
index:
39+
keyPattern: { x: 1 }
40+
prepareUnique: true
41+
- name: insertOne
42+
object: *collection0
43+
arguments:
44+
document: { _id: 3, x: 1 }
45+
expectError:
46+
errorCode: 11000 # DuplicateKey
47+
- name: modifyCollection
48+
object: *database0
49+
arguments:
50+
collection: *collection0Name
51+
index:
52+
keyPattern: { x: 1 }
53+
unique: true
54+
expectError:
55+
isClientError: false
56+
errorCode: 359 # CannotConvertIndexToUnique
57+
errorResponse:
58+
violations:
59+
- { ids: [ 1, 2 ] }
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"description": "aggregate-merge-errorResponse",
3+
"schemaVersion": "1.12",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
},
10+
{
11+
"database": {
12+
"id": "database0",
13+
"client": "client0",
14+
"databaseName": "crud-tests"
15+
}
16+
},
17+
{
18+
"collection": {
19+
"id": "collection0",
20+
"database": "database0",
21+
"collectionName": "test"
22+
}
23+
}
24+
],
25+
"initialData": [
26+
{
27+
"collectionName": "test",
28+
"databaseName": "crud-tests",
29+
"documents": [
30+
{
31+
"_id": 1,
32+
"x": 1
33+
},
34+
{
35+
"_id": 2,
36+
"x": 1
37+
}
38+
]
39+
}
40+
],
41+
"tests": [
42+
{
43+
"description": "aggregate $merge DuplicateKey error is accessible",
44+
"runOnRequirements": [
45+
{
46+
"minServerVersion": "5.1"
47+
}
48+
],
49+
"operations": [
50+
{
51+
"name": "aggregate",
52+
"object": "database0",
53+
"arguments": {
54+
"pipeline": [
55+
{
56+
"$documents": [
57+
{
58+
"_id": 2,
59+
"x": 1
60+
}
61+
]
62+
},
63+
{
64+
"$merge": {
65+
"into": "test",
66+
"whenMatched": "fail"
67+
}
68+
}
69+
]
70+
},
71+
"expectError": {
72+
"errorCode": 11000,
73+
"errorResponse": {
74+
"keyPattern": {
75+
"_id": 1
76+
},
77+
"keyValue": {
78+
"_id": 2
79+
}
80+
}
81+
}
82+
}
83+
]
84+
}
85+
]
86+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
description: "aggregate-merge-errorResponse"
2+
3+
schemaVersion: "1.12"
4+
5+
createEntities:
6+
- client:
7+
id: &client0 client0
8+
- database:
9+
id: &database0 database0
10+
client: *client0
11+
databaseName: &database0Name crud-tests
12+
- collection:
13+
id: &collection0 collection0
14+
database: *database0
15+
collectionName: &collection0Name test
16+
17+
initialData: &initialData
18+
- collectionName: *collection0Name
19+
databaseName: *database0Name
20+
documents:
21+
- { _id: 1, x: 1 }
22+
- { _id: 2, x: 1 }
23+
24+
tests:
25+
- description: "aggregate $merge DuplicateKey error is accessible"
26+
runOnRequirements:
27+
- minServerVersion: "5.1" # SERVER-59097
28+
operations:
29+
- name: aggregate
30+
object: *database0
31+
arguments:
32+
pipeline:
33+
- { $documents: [ { _id: 2, x: 1 } ] }
34+
- { $merge: { into: *collection0Name, whenMatched: "fail" } }
35+
expectError:
36+
errorCode: 11000 # DuplicateKey
37+
errorResponse:
38+
keyPattern: { _id: 1 }
39+
keyValue: { _id: 2 }
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"description": "bulkWrite-errorResponse",
3+
"schemaVersion": "1.12",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
},
10+
{
11+
"database": {
12+
"id": "database0",
13+
"client": "client0",
14+
"databaseName": "crud-tests"
15+
}
16+
},
17+
{
18+
"collection": {
19+
"id": "collection0",
20+
"database": "database0",
21+
"collectionName": "test"
22+
}
23+
}
24+
],
25+
"tests": [
26+
{
27+
"description": "bulkWrite operations support errorResponse assertions",
28+
"runOnRequirements": [
29+
{
30+
"minServerVersion": "4.0.0",
31+
"topologies": [
32+
"single",
33+
"replicaset"
34+
]
35+
},
36+
{
37+
"minServerVersion": "4.2.0",
38+
"topologies": [
39+
"sharded"
40+
]
41+
}
42+
],
43+
"operations": [
44+
{
45+
"name": "failPoint",
46+
"object": "testRunner",
47+
"arguments": {
48+
"client": "client0",
49+
"failPoint": {
50+
"configureFailPoint": "failCommand",
51+
"mode": {
52+
"times": 1
53+
},
54+
"data": {
55+
"failCommands": [
56+
"insert"
57+
],
58+
"errorCode": 8
59+
}
60+
}
61+
}
62+
},
63+
{
64+
"name": "bulkWrite",
65+
"object": "collection0",
66+
"arguments": {
67+
"requests": [
68+
{
69+
"insertOne": {
70+
"document": {
71+
"_id": 1
72+
}
73+
}
74+
}
75+
]
76+
},
77+
"expectError": {
78+
"errorCode": 8,
79+
"errorResponse": {
80+
"code": 8
81+
}
82+
}
83+
}
84+
]
85+
}
86+
]
87+
}

0 commit comments

Comments
 (0)