Skip to content

Commit

Permalink
test(NODE-3698): sync spec tests for crud operations with let option (
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Feb 18, 2022
1 parent f76635a commit 25d22b2
Show file tree
Hide file tree
Showing 18 changed files with 2,327 additions and 139 deletions.
103 changes: 0 additions & 103 deletions test/spec/crud/unified/aggregate-let.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,109 +56,6 @@
"minServerVersion": "5.0"
}
],
"operations": [
{
"name": "aggregate",
"object": "collection0",
"arguments": {
"pipeline": [
{
"$match": {
"$expr": {
"$eq": [
"$_id",
"$$id"
]
}
}
},
{
"$project": {
"_id": 0,
"x": "$$x",
"y": "$$y",
"rand": "$$rand"
}
}
],
"let": {
"id": 1,
"x": "foo",
"y": {
"$literal": "bar"
},
"rand": {
"$rand": {}
}
}
},
"expectResult": [
{
"x": "foo",
"y": "bar",
"rand": {
"$$type": "double"
}
}
]
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"aggregate": "coll0",
"pipeline": [
{
"$match": {
"$expr": {
"$eq": [
"$_id",
"$$id"
]
}
}
},
{
"$project": {
"_id": 0,
"x": "$$x",
"y": "$$y",
"rand": "$$rand"
}
}
],
"let": {
"id": 1,
"x": "foo",
"y": {
"$literal": "bar"
},
"rand": {
"$rand": {}
}
}
}
}
}
]
}
]
},
{
"description": "Aggregate with let option and dollar-prefixed $literal value",
"runOnRequirements": [
{
"minServerVersion": "5.0",
"topologies": [
"single",
"replicaset"
]
}
],
"operations": [
{
"name": "aggregate",
Expand Down
36 changes: 0 additions & 36 deletions test/spec/crud/unified/aggregate-let.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,9 @@ initialData: &initialData
documents: [ ]

tests:
# TODO: Once SERVER-57403 is resolved, this test can be removed in favor of
# the "dollar-prefixed $literal value" test below.
- description: "Aggregate with let option"
runOnRequirements:
- minServerVersion: "5.0"
operations:
- name: aggregate
object: *collection0
arguments:
pipeline: &pipeline0
# $match takes a query expression, so $expr is necessary to utilize
# an aggregate expression context and access "let" variables.
- $match: { $expr: { $eq: ["$_id", "$$id"] } }
- $project: { _id: 0, x: "$$x", y: "$$y", rand: "$$rand" }
# Values in "let" must be constant or closed expressions that do not
# depend on document values. This test demonstrates a basic constant
# value, a value wrapped with $literal (to avoid expression parsing),
# and a closed expression (e.g. $rand).
let: &let0
id: 1
x: foo
y: { $literal: "bar" }
rand: { $rand: {} }
expectResult:
- { x: "foo", y: "bar", rand: { $$type: "double" } }
expectEvents:
- client: *client0
events:
- commandStartedEvent:
command:
aggregate: *collection0Name
pipeline: *pipeline0
let: *let0

- description: "Aggregate with let option and dollar-prefixed $literal value"
runOnRequirements:
- minServerVersion: "5.0"
# TODO: Remove topology restrictions once SERVER-57403 is resolved
topologies: ["single", "replicaset"]
operations:
- name: aggregate
object: *collection0
Expand Down
201 changes: 201 additions & 0 deletions test/spec/crud/unified/deleteMany-let.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
{
"description": "deleteMany-let",
"schemaVersion": "1.0",
"createEntities": [
{
"client": {
"id": "client0",
"observeEvents": [
"commandStartedEvent"
]
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "crud-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "coll0"
}
}
],
"initialData": [
{
"collectionName": "coll0",
"databaseName": "crud-tests",
"documents": [
{
"_id": 1
},
{
"_id": 2,
"name": "name"
},
{
"_id": 3,
"name": "name"
}
]
}
],
"tests": [
{
"description": "deleteMany with let option",
"runOnRequirements": [
{
"minServerVersion": "5.0"
}
],
"operations": [
{
"name": "deleteMany",
"object": "collection0",
"arguments": {
"filter": {
"$expr": {
"$eq": [
"$name",
"$$name"
]
}
},
"let": {
"name": "name"
}
},
"expectResult": {
"deletedCount": 2
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"delete": "coll0",
"deletes": [
{
"q": {
"$expr": {
"$eq": [
"$name",
"$$name"
]
}
},
"limit": 0
}
],
"let": {
"name": "name"
}
}
}
}
]
}
],
"outcome": [
{
"collectionName": "coll0",
"databaseName": "crud-tests",
"documents": [
{
"_id": 1
}
]
}
]
},
{
"description": "deleteMany with let option unsupported (server-side error)",
"runOnRequirements": [
{
"minServerVersion": "3.6.0",
"maxServerVersion": "4.4.99"
}
],
"operations": [
{
"name": "deleteMany",
"object": "collection0",
"arguments": {
"filter": {
"$expr": {
"$eq": [
"$name",
"$$name"
]
}
},
"let": {
"name": "name"
}
},
"expectError": {
"errorContains": "'delete.let' is an unknown field",
"isClientError": false
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"delete": "coll0",
"deletes": [
{
"q": {
"$expr": {
"$eq": [
"$name",
"$$name"
]
}
},
"limit": 0
}
],
"let": {
"name": "name"
}
}
}
}
]
}
],
"outcome": [
{
"collectionName": "coll0",
"databaseName": "crud-tests",
"documents": [
{
"_id": 1
},
{
"_id": 2,
"name": "name"
},
{
"_id": 3,
"name": "name"
}
]
}
]
}
]
}

0 comments on commit 25d22b2

Please sign in to comment.