Skip to content

Commit daf9e07

Browse files
authored
DRIVERS-2573: Reference test for $$matchAsDocument and $$matchAsRoot (#1706)
Renames the test file for $$lte for consistency. Also revises the comment within, which previously referred to the incorrect schema version for CSOT.
1 parent 39094b0 commit daf9e07

10 files changed

+789
-3
lines changed

source/unified-test-format/tests/valid-fail/operator-matchAsDocument.json

Lines changed: 205 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
description: operator-matchAsDocument
2+
3+
schemaVersion: "1.13"
4+
5+
createEntities:
6+
- client:
7+
id: &client0 client0
8+
- database:
9+
id: &database0 database0
10+
client: *client0
11+
databaseName: &database0Name test
12+
- collection:
13+
id: &collection0 collection0
14+
database: *database0
15+
collectionName: &collection0Name coll0
16+
17+
initialData:
18+
- collectionName: *collection0Name
19+
databaseName: *database0Name
20+
documents:
21+
- { _id: 1, json: '{ "x": 1, "y": 2 }' }
22+
# Documents with non-objects or invalid JSON
23+
- { _id: 2, json: '1' }
24+
- { _id: 3, json: '[ "foo" ]' }
25+
- { _id: 4, json: '{ "x" }' }
26+
27+
tests:
28+
- description: matchAsDocument with non-matching filter
29+
operations:
30+
- name: find
31+
object: *collection0
32+
arguments:
33+
filter: { _id : 1 }
34+
limit: 1
35+
expectResult:
36+
- { _id: 1, json: { $$matchAsDocument: { x: 1, y: "two" } } }
37+
-
38+
description: matchAsDocument evaluates special operators
39+
operations:
40+
- name: find
41+
object: *collection0
42+
arguments:
43+
filter: { _id : 1 }
44+
limit: 1
45+
expectResult:
46+
- { _id: 1, json: { $$matchAsDocument: { x: 1, y: { $$exists: false } } } }
47+
-
48+
description: matchAsDocument does not permit extra fields
49+
operations:
50+
- name: find
51+
object: *collection0
52+
arguments:
53+
filter: { _id : 1 }
54+
limit: 1
55+
expectResult:
56+
- { _id: 1, json: { $$matchAsDocument: { x: 1 } } }
57+
-
58+
description: matchAsDocument expects JSON object but given scalar
59+
operations:
60+
- name: find
61+
object: *collection0
62+
arguments:
63+
filter: { _id : 2 }
64+
limit: 1
65+
expectResult:
66+
# The following $$matchAsRoot expression would match any document, so
67+
# this ensures the failure is due to the actual value.
68+
- { _id: 2, json: &match_any_document { $$matchAsDocument: { $$matchAsRoot: { } } } }
69+
-
70+
description: matchAsDocument expects JSON object but given array
71+
operations:
72+
- name: find
73+
object: *collection0
74+
arguments:
75+
filter: { _id : 3 }
76+
limit: 1
77+
expectResult:
78+
- { _id: 3, json: *match_any_document }
79+
-
80+
description: matchAsDocument fails to decode Extended JSON
81+
operations:
82+
- name: find
83+
object: *collection0
84+
arguments:
85+
filter: { _id : 4 }
86+
limit: 1
87+
expectResult:
88+
- { _id: 4, json: *match_any_document }

source/unified-test-format/tests/valid-fail/operator-matchAsRoot.json

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
description: operator-matchAsRoot
2+
3+
schemaVersion: "1.13"
4+
5+
createEntities:
6+
- client:
7+
id: &client0 client0
8+
- database:
9+
id: &database0 database0
10+
client: *client0
11+
databaseName: &database0Name test
12+
- collection:
13+
id: &collection0 collection0
14+
database: *database0
15+
collectionName: &collection0Name coll0
16+
17+
initialData:
18+
- collectionName: *collection0Name
19+
databaseName: *database0Name
20+
documents:
21+
- { _id: 1, x: { y: 2, z: 3 } }
22+
23+
tests:
24+
-
25+
description: matchAsRoot with nested document does not match
26+
operations:
27+
- name: find
28+
object: *collection0
29+
arguments:
30+
filter: { _id : 1 }
31+
limit: 1
32+
expectResult:
33+
- { _id: 1, x: { $$matchAsRoot: { y: 3 } } }

0 commit comments

Comments
 (0)