@@ -126,6 +126,10 @@ func TestMongoHelpers(t *testing.T) {
126
126
arr , _ = bsoncore .AppendDocumentEnd (arr , dindex )
127
127
arr , _ = bsoncore .AppendArrayEnd (arr , index )
128
128
129
+ index , doc := bsoncore .AppendDocumentStart (nil )
130
+ doc = bsoncore .AppendInt32Element (doc , "x" , 1 )
131
+ doc , _ = bsoncore .AppendDocumentEnd (doc , index )
132
+
129
133
testCases := []struct {
130
134
name string
131
135
pipeline interface {}
@@ -342,6 +346,48 @@ func TestMongoHelpers(t *testing.T) {
342
346
true ,
343
347
nil ,
344
348
},
349
+ {
350
+ "semantic single document/bson.D" ,
351
+ bson.D {{"x" , 1 }},
352
+ nil ,
353
+ false ,
354
+ errors .New ("primitive.D is not an allowed pipeline type as it represents a single document. Use bson.A or mongo.Pipeline instead" ),
355
+ },
356
+ {
357
+ "semantic single document/bson.Raw" ,
358
+ bson .Raw (doc ),
359
+ nil ,
360
+ false ,
361
+ errors .New ("bson.Raw is not an allowed pipeline type as it represents a single document. Use bson.A or mongo.Pipeline instead" ),
362
+ },
363
+ {
364
+ "semantic single document/bsoncore.Document" ,
365
+ bsoncore .Document (doc ),
366
+ nil ,
367
+ false ,
368
+ errors .New ("bsoncore.Document is not an allowed pipeline type as it represents a single document. Use bson.A or mongo.Pipeline instead" ),
369
+ },
370
+ {
371
+ "semantic single document/empty bson.D" ,
372
+ bson.D {},
373
+ bson.A {},
374
+ false ,
375
+ nil ,
376
+ },
377
+ {
378
+ "semantic single document/empty bson.Raw" ,
379
+ bson.Raw {},
380
+ bson.A {},
381
+ false ,
382
+ nil ,
383
+ },
384
+ {
385
+ "semantic single document/empty bsoncore.Document" ,
386
+ bsoncore.Document {},
387
+ bson.A {},
388
+ false ,
389
+ nil ,
390
+ },
345
391
}
346
392
347
393
for _ , tc := range testCases {
0 commit comments