Skip to content

Commit 3a58fc6

Browse files
authored
DRIVERS-776: Add tests for aggregate with $out using let option (#1014)
1 parent 9465cda commit 3a58fc6

File tree

2 files changed

+236
-0
lines changed

2 files changed

+236
-0
lines changed

source/crud/tests/unified/aggregate-let.json

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
"database": "database0",
2424
"collectionName": "coll0"
2525
}
26+
},
27+
{
28+
"collection": {
29+
"id": "collection1",
30+
"database": "database0",
31+
"collectionName": "coll1"
32+
}
2633
}
2734
],
2835
"initialData": [
@@ -34,6 +41,11 @@
3441
"_id": 1
3542
}
3643
]
44+
},
45+
{
46+
"collectionName": "coll1",
47+
"databaseName": "crud-tests",
48+
"documents": []
3749
}
3850
],
3951
"tests": [
@@ -293,6 +305,174 @@
293305
]
294306
}
295307
]
308+
},
309+
{
310+
"description": "Aggregate to collection with let option",
311+
"runOnRequirements": [
312+
{
313+
"minServerVersion": "5.0"
314+
}
315+
],
316+
"operations": [
317+
{
318+
"name": "aggregate",
319+
"object": "collection0",
320+
"arguments": {
321+
"pipeline": [
322+
{
323+
"$match": {
324+
"$expr": {
325+
"$eq": [
326+
"$_id",
327+
"$$id"
328+
]
329+
}
330+
}
331+
},
332+
{
333+
"$project": {
334+
"_id": 1
335+
}
336+
},
337+
{
338+
"$out": "coll1"
339+
}
340+
],
341+
"let": {
342+
"id": 1
343+
}
344+
}
345+
}
346+
],
347+
"expectEvents": [
348+
{
349+
"client": "client0",
350+
"events": [
351+
{
352+
"commandStartedEvent": {
353+
"command": {
354+
"aggregate": "coll0",
355+
"pipeline": [
356+
{
357+
"$match": {
358+
"$expr": {
359+
"$eq": [
360+
"$_id",
361+
"$$id"
362+
]
363+
}
364+
}
365+
},
366+
{
367+
"$project": {
368+
"_id": 1
369+
}
370+
},
371+
{
372+
"$out": "coll1"
373+
}
374+
],
375+
"let": {
376+
"id": 1
377+
}
378+
}
379+
}
380+
}
381+
]
382+
}
383+
],
384+
"outcome": [
385+
{
386+
"collectionName": "coll1",
387+
"databaseName": "crud-tests",
388+
"documents": [
389+
{
390+
"_id": 1
391+
}
392+
]
393+
}
394+
]
395+
},
396+
{
397+
"description": "Aggregate to collection with let option unsupported (server-side error)",
398+
"runOnRequirements": [
399+
{
400+
"minServerVersion": "2.6.0",
401+
"maxServerVersion": "4.4.99"
402+
}
403+
],
404+
"operations": [
405+
{
406+
"name": "aggregate",
407+
"object": "collection0",
408+
"arguments": {
409+
"pipeline": [
410+
{
411+
"$match": {
412+
"$expr": {
413+
"$eq": [
414+
"$_id",
415+
"$$id"
416+
]
417+
}
418+
}
419+
},
420+
{
421+
"$project": {
422+
"_id": 1
423+
}
424+
},
425+
{
426+
"$out": "coll1"
427+
}
428+
],
429+
"let": {
430+
"id": 1
431+
}
432+
},
433+
"expectError": {
434+
"errorContains": "unrecognized field 'let'",
435+
"isClientError": false
436+
}
437+
}
438+
],
439+
"expectEvents": [
440+
{
441+
"client": "client0",
442+
"events": [
443+
{
444+
"commandStartedEvent": {
445+
"command": {
446+
"aggregate": "coll0",
447+
"pipeline": [
448+
{
449+
"$match": {
450+
"$expr": {
451+
"$eq": [
452+
"$_id",
453+
"$$id"
454+
]
455+
}
456+
}
457+
},
458+
{
459+
"$project": {
460+
"_id": 1
461+
}
462+
},
463+
{
464+
"$out": "coll1"
465+
}
466+
],
467+
"let": {
468+
"id": 1
469+
}
470+
}
471+
}
472+
}
473+
]
474+
}
475+
]
296476
}
297477
]
298478
}

source/crud/tests/unified/aggregate-let.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ createEntities:
1414
id: &collection0 collection0
1515
database: *database0
1616
collectionName: &collection0Name coll0
17+
- collection:
18+
id: &collection1 collection1
19+
database: *database0
20+
collectionName: &collection1Name coll1
1721

1822
initialData: &initialData
1923
- collectionName: *collection0Name
2024
databaseName: *database0Name
2125
documents:
2226
- { _id: 1 }
27+
- collectionName: *collection1Name
28+
databaseName: *database0Name
29+
documents: [ ]
2330

2431
tests:
2532
# TODO: Once SERVER-57403 is resolved, this test can be removed in favor of
@@ -115,3 +122,52 @@ tests:
115122
aggregate: *collection0Name
116123
pipeline: *pipeline1
117124
let: *let1
125+
126+
- description: "Aggregate to collection with let option"
127+
runOnRequirements:
128+
- minServerVersion: "5.0"
129+
operations:
130+
- name: aggregate
131+
object: *collection0
132+
arguments:
133+
pipeline: &pipeline2
134+
- $match: { $expr: { $eq: ["$_id", "$$id"] } }
135+
- $project: { _id: 1 }
136+
- $out: *collection1Name
137+
let: &let2
138+
id: 1
139+
expectEvents:
140+
- client: *client0
141+
events:
142+
- commandStartedEvent:
143+
command:
144+
aggregate: *collection0Name
145+
pipeline: *pipeline2
146+
let: *let2
147+
outcome:
148+
- collectionName: *collection1Name
149+
databaseName: *database0Name
150+
documents:
151+
- { _id: 1 }
152+
153+
- description: "Aggregate to collection with let option unsupported (server-side error)"
154+
runOnRequirements:
155+
- minServerVersion: "2.6.0"
156+
maxServerVersion: "4.4.99"
157+
operations:
158+
- name: aggregate
159+
object: *collection0
160+
arguments:
161+
pipeline: *pipeline2
162+
let: *let2
163+
expectError:
164+
errorContains: "unrecognized field 'let'"
165+
isClientError: false
166+
expectEvents:
167+
- client: *client0
168+
events:
169+
- commandStartedEvent:
170+
command:
171+
aggregate: *collection0Name
172+
pipeline: *pipeline2
173+
let: *let2

0 commit comments

Comments
 (0)