Skip to content

Commit 75b6b0b

Browse files
authored
GODRIVER-1870 Remove insertedCount assertions and improve usage of unsetOrMatches (#691)
1 parent c3b779c commit 75b6b0b

File tree

9 files changed

+82
-72
lines changed

9 files changed

+82
-72
lines changed

data/crud/unified/insertMany-dots_and_dollars.json

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@
5353
]
5454
},
5555
"expectResult": {
56-
"insertedCount": 1,
57-
"insertedIds": {
58-
"$$unsetOrMatches": {
59-
"0": 1
56+
"$$unsetOrMatches": {
57+
"insertedIds": {
58+
"$$unsetOrMatches": {
59+
"0": 1
60+
}
6061
}
6162
}
6263
}
@@ -162,10 +163,11 @@
162163
]
163164
},
164165
"expectResult": {
165-
"insertedCount": 1,
166-
"insertedIds": {
167-
"$$unsetOrMatches": {
168-
"0": 1
166+
"$$unsetOrMatches": {
167+
"insertedIds": {
168+
"$$unsetOrMatches": {
169+
"0": 1
170+
}
169171
}
170172
}
171173
}
@@ -221,10 +223,11 @@
221223
]
222224
},
223225
"expectResult": {
224-
"insertedCount": 1,
225-
"insertedIds": {
226-
"$$unsetOrMatches": {
227-
"0": 1
226+
"$$unsetOrMatches": {
227+
"insertedIds": {
228+
"$$unsetOrMatches": {
229+
"0": 1
230+
}
228231
}
229232
}
230233
}
@@ -284,10 +287,11 @@
284287
]
285288
},
286289
"expectResult": {
287-
"insertedCount": 1,
288-
"insertedIds": {
289-
"$$unsetOrMatches": {
290-
"0": 1
290+
"$$unsetOrMatches": {
291+
"insertedIds": {
292+
"$$unsetOrMatches": {
293+
"0": 1
294+
}
291295
}
292296
}
293297
}

data/crud/unified/insertMany-dots_and_dollars.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ tests:
3131
documents:
3232
- &dollarPrefixedKey { _id: 1, $a: 1 }
3333
expectResult: &insertResult
34-
insertedCount: 1
35-
insertedIds: { $$unsetOrMatches: { 0: 1 } }
34+
# InsertManyResult is optional because all of its fields are optional
35+
$$unsetOrMatches: { insertedIds: { $$unsetOrMatches: { 0: 1 } } }
3636
expectEvents: &expectEventsDollarPrefixedKey
3737
- client: *client0
3838
events:

data/crud/unified/insertOne-dots_and_dollars.json

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@
6363
}
6464
},
6565
"expectResult": {
66-
"insertedCount": 1,
67-
"insertedId": {
68-
"$$unsetOrMatches": 1
66+
"$$unsetOrMatches": {
67+
"insertedId": {
68+
"$$unsetOrMatches": 1
69+
}
6970
}
7071
}
7172
}
@@ -166,9 +167,10 @@
166167
}
167168
},
168169
"expectResult": {
169-
"insertedCount": 1,
170-
"insertedId": {
171-
"$$unsetOrMatches": 1
170+
"$$unsetOrMatches": {
171+
"insertedId": {
172+
"$$unsetOrMatches": 1
173+
}
172174
}
173175
}
174176
}
@@ -221,9 +223,10 @@
221223
}
222224
},
223225
"expectResult": {
224-
"insertedCount": 1,
225-
"insertedId": {
226-
"$$unsetOrMatches": 1
226+
"$$unsetOrMatches": {
227+
"insertedId": {
228+
"$$unsetOrMatches": 1
229+
}
227230
}
228231
}
229232
}
@@ -280,9 +283,10 @@
280283
}
281284
},
282285
"expectResult": {
283-
"insertedCount": 1,
284-
"insertedId": {
285-
"$$unsetOrMatches": 1
286+
"$$unsetOrMatches": {
287+
"insertedId": {
288+
"$$unsetOrMatches": 1
289+
}
286290
}
287291
}
288292
}
@@ -390,10 +394,11 @@
390394
}
391395
},
392396
"expectResult": {
393-
"insertedCount": 1,
394-
"insertedId": {
395-
"$$unsetOrMatches": {
396-
"a.b": 1
397+
"$$unsetOrMatches": {
398+
"insertedId": {
399+
"$$unsetOrMatches": {
400+
"a.b": 1
401+
}
397402
}
398403
}
399404
}
@@ -501,9 +506,10 @@
501506
}
502507
},
503508
"expectResult": {
504-
"insertedCount": 1,
505-
"insertedId": {
506-
"$$unsetOrMatches": 1
509+
"$$unsetOrMatches": {
510+
"insertedId": {
511+
"$$unsetOrMatches": 1
512+
}
507513
}
508514
}
509515
}
@@ -564,8 +570,10 @@
564570
}
565571
},
566572
"expectResult": {
567-
"acknowledged": {
568-
"$$unsetOrMatches": false
573+
"$$unsetOrMatches": {
574+
"acknowledged": {
575+
"$$unsetOrMatches": false
576+
}
569577
}
570578
}
571579
}

data/crud/unified/insertOne-dots_and_dollars.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ tests:
3636
arguments:
3737
document: &dollarPrefixedKey { _id: 1, $a: 1 }
3838
expectResult: &insertResult
39-
insertedCount: 1
40-
insertedId: { $$unsetOrMatches: 1 }
39+
# InsertOneResult is optional because all of its fields are optional
40+
$$unsetOrMatches: { insertedId: { $$unsetOrMatches: 1 } }
4141
expectEvents: &expectEventsDollarPrefixedKey
4242
- client: *client0
4343
events:
@@ -156,8 +156,8 @@ tests:
156156
arguments:
157157
document: &dottedKeyInId { _id: { a.b: 1 } }
158158
expectResult:
159-
insertedCount: 1
160-
insertedId: { $$unsetOrMatches: { a.b: 1 } }
159+
# InsertOneResult is optional because all of its fields are optional
160+
$$unsetOrMatches: { insertedId: { $$unsetOrMatches: { a.b: 1 } } }
161161
expectEvents: &expectEventsDottedKeyInId
162162
- client: *client0
163163
events:
@@ -224,7 +224,8 @@ tests:
224224
arguments:
225225
document: *dollarPrefixedKeyInId
226226
expectResult:
227-
acknowledged: { $$unsetOrMatches: false }
227+
# InsertOneResult is optional because all of its fields are optional
228+
$$unsetOrMatches: { acknowledged: { $$unsetOrMatches: false } }
228229
expectEvents:
229230
- client: *client0
230231
events:

data/unified-test-format/valid-pass/poc-crud.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,14 @@
242242
},
243243
"expectError": {
244244
"expectResult": {
245-
"deletedCount": 0,
246-
"insertedCount": 2,
247-
"matchedCount": 0,
248-
"modifiedCount": 0,
249-
"upsertedCount": 0,
250-
"upsertedIds": {}
245+
"$$unsetOrMatches": {
246+
"deletedCount": 0,
247+
"insertedCount": 2,
248+
"matchedCount": 0,
249+
"modifiedCount": 0,
250+
"upsertedCount": 0,
251+
"upsertedIds": {}
252+
}
251253
}
252254
}
253255
}

data/unified-test-format/valid-pass/poc-crud.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,19 @@ tests:
101101
ordered: false
102102
expectError:
103103
expectResult:
104-
deletedCount: 0
105-
insertedCount: 2
106-
# Since the map of insertedIds is generated before execution it
107-
# could indicate inserts that did not actually succeed. We omit
108-
# this field rather than expect drivers to provide an accurate
109-
# map filtered by write errors.
110-
matchedCount: 0
111-
modifiedCount: 0
112-
upsertedCount: 0
113-
upsertedIds: { }
104+
# insertMany throws BulkWriteException, which may optionally include
105+
# an intermediary BulkWriteResult
106+
$$unsetOrMatches:
107+
deletedCount: 0
108+
insertedCount: 2
109+
# Since the map of insertedIds is generated before execution it
110+
# could indicate inserts that did not actually succeed. We omit
111+
# this field rather than expect drivers to provide an accurate
112+
# map filtered by write errors.
113+
matchedCount: 0
114+
modifiedCount: 0
115+
upsertedCount: 0
116+
upsertedIds: { }
114117
outcome:
115118
- collectionName: *collection1Name
116119
databaseName: *database0Name

data/unified-test-format/valid-pass/poc-retryable-writes.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,6 @@
298298
},
299299
"expectResult": {
300300
"$$unsetOrMatches": {
301-
"insertedCount": {
302-
"$$unsetOrMatches": 2
303-
},
304301
"insertedIds": {
305302
"$$unsetOrMatches": {
306303
"0": 3,

data/unified-test-format/valid-pass/poc-retryable-writes.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ tests:
141141
- { _id: 4, x: 44 }
142142
ordered: true
143143
expectResult:
144-
$$unsetOrMatches:
145-
insertedCount: { $$unsetOrMatches: 2 }
146-
insertedIds: { $$unsetOrMatches: { 0: 3, 1: 4 } }
144+
# InsertManyResult is optional because all of its fields are optional
145+
$$unsetOrMatches: { insertedIds: { $$unsetOrMatches: { 0: 3, 1: 4 } } }
147146
outcome:
148147
- collectionName: *collectionName
149148
databaseName: *databaseName

mongo/integration/unified/collection_operation_execution.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,16 +740,12 @@ func executeInsertOne(ctx context.Context, operation *operation) (*operationResu
740740
res, err := coll.InsertOne(ctx, document, opts)
741741
raw := emptyCoreDocument
742742
if res != nil {
743-
idT, idData, err := bson.MarshalValue(res.InsertedID)
743+
t, data, err := bson.MarshalValue(res.InsertedID)
744744
if err != nil {
745745
return nil, fmt.Errorf("error converting InsertedID field to BSON: %v", err)
746746
}
747-
748-
// Some spec tests assert insertedCount for insertOne, so manually add insertedCount of 1.
749-
countT, countData, _ := bson.MarshalValue(1)
750747
raw = bsoncore.NewDocumentBuilder().
751-
AppendValue("insertedId", bsoncore.Value{Type: idT, Data: idData}).
752-
AppendValue("insertedCount", bsoncore.Value{Type: countT, Data: countData}).
748+
AppendValue("insertedId", bsoncore.Value{Type: t, Data: data}).
753749
Build()
754750
}
755751
return newDocumentResult(raw, err), nil

0 commit comments

Comments
 (0)