Skip to content

Commit cb91bb8

Browse files
authored
CSHARP-5372: Sync tests for null insert/upsert _id values (mongodb#1666)
1 parent 2c7fb15 commit cb91bb8

File tree

2 files changed

+350
-0
lines changed

2 files changed

+350
-0
lines changed
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
{
2+
"description": "create-null-ids",
3+
"schemaVersion": "1.0",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client",
8+
"observeEvents": [
9+
"commandStartedEvent"
10+
]
11+
}
12+
},
13+
{
14+
"database": {
15+
"id": "database",
16+
"client": "client",
17+
"databaseName": "crud_id"
18+
}
19+
},
20+
{
21+
"collection": {
22+
"id": "collection",
23+
"database": "database",
24+
"collectionName": "type_tests"
25+
}
26+
}
27+
],
28+
"initialData": [
29+
{
30+
"collectionName": "type_tests",
31+
"databaseName": "crud_id",
32+
"documents": []
33+
}
34+
],
35+
"tests": [
36+
{
37+
"description": "inserting _id with type null via insertOne",
38+
"operations": [
39+
{
40+
"name": "insertOne",
41+
"object": "collection",
42+
"arguments": {
43+
"document": {
44+
"_id": null
45+
}
46+
}
47+
},
48+
{
49+
"name": "countDocuments",
50+
"object": "collection",
51+
"arguments": {
52+
"filter": {
53+
"_id": {
54+
"$type": "null"
55+
}
56+
}
57+
},
58+
"expectResult": 1
59+
}
60+
]
61+
},
62+
{
63+
"description": "inserting _id with type null via insertMany",
64+
"operations": [
65+
{
66+
"name": "insertMany",
67+
"object": "collection",
68+
"arguments": {
69+
"documents": [
70+
{
71+
"_id": null
72+
}
73+
]
74+
}
75+
},
76+
{
77+
"name": "countDocuments",
78+
"object": "collection",
79+
"arguments": {
80+
"filter": {
81+
"_id": {
82+
"$type": "null"
83+
}
84+
}
85+
},
86+
"expectResult": 1
87+
}
88+
]
89+
},
90+
{
91+
"description": "inserting _id with type null via updateOne",
92+
"operations": [
93+
{
94+
"name": "updateOne",
95+
"object": "collection",
96+
"arguments": {
97+
"filter": {
98+
"_id": null
99+
},
100+
"update": {
101+
"$unset": {
102+
"a": ""
103+
}
104+
},
105+
"upsert": true
106+
}
107+
},
108+
{
109+
"name": "countDocuments",
110+
"object": "collection",
111+
"arguments": {
112+
"filter": {
113+
"_id": {
114+
"$type": "null"
115+
}
116+
}
117+
},
118+
"expectResult": 1
119+
}
120+
]
121+
},
122+
{
123+
"description": "inserting _id with type null via updateMany",
124+
"operations": [
125+
{
126+
"name": "updateMany",
127+
"object": "collection",
128+
"arguments": {
129+
"filter": {
130+
"_id": null
131+
},
132+
"update": {
133+
"$unset": {
134+
"a": ""
135+
}
136+
},
137+
"upsert": true
138+
}
139+
},
140+
{
141+
"name": "countDocuments",
142+
"object": "collection",
143+
"arguments": {
144+
"filter": {
145+
"_id": {
146+
"$type": "null"
147+
}
148+
}
149+
},
150+
"expectResult": 1
151+
}
152+
]
153+
},
154+
{
155+
"description": "inserting _id with type null via replaceOne",
156+
"operations": [
157+
{
158+
"name": "replaceOne",
159+
"object": "collection",
160+
"arguments": {
161+
"filter": {},
162+
"replacement": {
163+
"_id": null
164+
},
165+
"upsert": true
166+
}
167+
},
168+
{
169+
"name": "countDocuments",
170+
"object": "collection",
171+
"arguments": {
172+
"filter": {
173+
"_id": {
174+
"$type": "null"
175+
}
176+
}
177+
},
178+
"expectResult": 1
179+
}
180+
]
181+
},
182+
{
183+
"description": "inserting _id with type null via bulkWrite",
184+
"operations": [
185+
{
186+
"name": "bulkWrite",
187+
"object": "collection",
188+
"arguments": {
189+
"requests": [
190+
{
191+
"insertOne": {
192+
"document": {
193+
"_id": null
194+
}
195+
}
196+
}
197+
]
198+
}
199+
},
200+
{
201+
"name": "countDocuments",
202+
"object": "collection",
203+
"arguments": {
204+
"filter": {
205+
"_id": {
206+
"$type": "null"
207+
}
208+
}
209+
},
210+
"expectResult": 1
211+
}
212+
]
213+
},
214+
{
215+
"description": "inserting _id with type null via clientBulkWrite",
216+
"runOnRequirements": [
217+
{
218+
"minServerVersion": "8.0"
219+
}
220+
],
221+
"operations": [
222+
{
223+
"name": "clientBulkWrite",
224+
"object": "client",
225+
"arguments": {
226+
"models": [
227+
{
228+
"insertOne": {
229+
"namespace": "crud_id.type_tests",
230+
"document": {
231+
"_id": null
232+
}
233+
}
234+
}
235+
]
236+
}
237+
},
238+
{
239+
"name": "countDocuments",
240+
"object": "collection",
241+
"arguments": {
242+
"filter": {
243+
"_id": {
244+
"$type": "null"
245+
}
246+
}
247+
},
248+
"expectResult": 1
249+
}
250+
]
251+
}
252+
]
253+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
description: create-null-ids
2+
schemaVersion: '1.0'
3+
4+
createEntities:
5+
- client:
6+
id: client
7+
observeEvents:
8+
- commandStartedEvent
9+
- database:
10+
id: &database database
11+
client: client
12+
databaseName: crud_id
13+
- collection:
14+
id: &collection collection
15+
database: *database
16+
collectionName: type_tests
17+
18+
initialData:
19+
- collectionName: type_tests
20+
databaseName: crud_id
21+
documents: []
22+
23+
tests:
24+
25+
- description: inserting _id with type null via insertOne
26+
operations:
27+
- name: insertOne
28+
object: *collection
29+
arguments: {document: &null_id {_id: null}}
30+
# We use countDocuments with a $type query to verify the insert of the correct BSON type
31+
# this is to avoid client side type conversions (potentially common: undefined -> null)
32+
- name: countDocuments
33+
object: *collection
34+
arguments: {filter: &null_id_filter {_id: {$type: 'null'}}}
35+
expectResult: 1
36+
37+
- description: inserting _id with type null via insertMany
38+
operations:
39+
- name: insertMany
40+
object: *collection
41+
arguments: {documents: [*null_id]}
42+
- name: countDocuments
43+
object: *collection
44+
arguments: {filter: *null_id_filter}
45+
expectResult: 1
46+
47+
- description: inserting _id with type null via updateOne
48+
operations:
49+
- name: updateOne
50+
object: *collection
51+
arguments: {filter: *null_id, update: {$unset: {a: ''}}, upsert: true}
52+
- name: countDocuments
53+
object: *collection
54+
arguments: {filter: *null_id_filter}
55+
expectResult: 1
56+
57+
- description: inserting _id with type null via updateMany
58+
operations:
59+
- name: updateMany
60+
object: *collection
61+
arguments: {filter: *null_id, update: {$unset: {a: ''}}, upsert: true}
62+
- name: countDocuments
63+
object: *collection
64+
arguments: {filter: *null_id_filter}
65+
expectResult: 1
66+
67+
- description: inserting _id with type null via replaceOne
68+
operations:
69+
- name: replaceOne
70+
object: *collection
71+
arguments: {filter: {}, replacement: *null_id, upsert: true}
72+
- name: countDocuments
73+
object: *collection
74+
arguments: {filter: *null_id_filter}
75+
expectResult: 1
76+
77+
- description: inserting _id with type null via bulkWrite
78+
operations:
79+
- name: bulkWrite
80+
object: *collection
81+
arguments: {requests: [{insertOne: {document: *null_id}}]}
82+
- name: countDocuments
83+
object: *collection
84+
arguments: {filter: *null_id_filter}
85+
expectResult: 1
86+
87+
- description: inserting _id with type null via clientBulkWrite
88+
runOnRequirements:
89+
- minServerVersion: '8.0'
90+
operations:
91+
- name: clientBulkWrite
92+
object: client
93+
arguments: {models: [{insertOne: {namespace: crud_id.type_tests, document: *null_id}}]}
94+
- name: countDocuments
95+
object: *collection
96+
arguments: {filter: *null_id_filter}
97+
expectResult: 1

0 commit comments

Comments
 (0)