Skip to content

Commit

Permalink
RUST-2067 Sync tests for null insert/upsert _id values (#1238)
Browse files Browse the repository at this point in the history
  • Loading branch information
abr-egn authored Nov 1, 2024
1 parent 3bf5e97 commit 288d796
Show file tree
Hide file tree
Showing 2 changed files with 350 additions and 0 deletions.
253 changes: 253 additions & 0 deletions src/test/spec/json/crud/unified/create-null-ids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
{
"description": "create-null-ids",
"schemaVersion": "1.0",
"createEntities": [
{
"client": {
"id": "client",
"observeEvents": [
"commandStartedEvent"
]
}
},
{
"database": {
"id": "database",
"client": "client",
"databaseName": "crud_id"
}
},
{
"collection": {
"id": "collection",
"database": "database",
"collectionName": "type_tests"
}
}
],
"initialData": [
{
"collectionName": "type_tests",
"databaseName": "crud_id",
"documents": []
}
],
"tests": [
{
"description": "inserting _id with type null via insertOne",
"operations": [
{
"name": "insertOne",
"object": "collection",
"arguments": {
"document": {
"_id": null
}
}
},
{
"name": "countDocuments",
"object": "collection",
"arguments": {
"filter": {
"_id": {
"$type": "null"
}
}
},
"expectResult": 1
}
]
},
{
"description": "inserting _id with type null via insertMany",
"operations": [
{
"name": "insertMany",
"object": "collection",
"arguments": {
"documents": [
{
"_id": null
}
]
}
},
{
"name": "countDocuments",
"object": "collection",
"arguments": {
"filter": {
"_id": {
"$type": "null"
}
}
},
"expectResult": 1
}
]
},
{
"description": "inserting _id with type null via updateOne",
"operations": [
{
"name": "updateOne",
"object": "collection",
"arguments": {
"filter": {
"_id": null
},
"update": {
"$unset": {
"a": ""
}
},
"upsert": true
}
},
{
"name": "countDocuments",
"object": "collection",
"arguments": {
"filter": {
"_id": {
"$type": "null"
}
}
},
"expectResult": 1
}
]
},
{
"description": "inserting _id with type null via updateMany",
"operations": [
{
"name": "updateMany",
"object": "collection",
"arguments": {
"filter": {
"_id": null
},
"update": {
"$unset": {
"a": ""
}
},
"upsert": true
}
},
{
"name": "countDocuments",
"object": "collection",
"arguments": {
"filter": {
"_id": {
"$type": "null"
}
}
},
"expectResult": 1
}
]
},
{
"description": "inserting _id with type null via replaceOne",
"operations": [
{
"name": "replaceOne",
"object": "collection",
"arguments": {
"filter": {},
"replacement": {
"_id": null
},
"upsert": true
}
},
{
"name": "countDocuments",
"object": "collection",
"arguments": {
"filter": {
"_id": {
"$type": "null"
}
}
},
"expectResult": 1
}
]
},
{
"description": "inserting _id with type null via bulkWrite",
"operations": [
{
"name": "bulkWrite",
"object": "collection",
"arguments": {
"requests": [
{
"insertOne": {
"document": {
"_id": null
}
}
}
]
}
},
{
"name": "countDocuments",
"object": "collection",
"arguments": {
"filter": {
"_id": {
"$type": "null"
}
}
},
"expectResult": 1
}
]
},
{
"description": "inserting _id with type null via clientBulkWrite",
"runOnRequirements": [
{
"minServerVersion": "8.0"
}
],
"operations": [
{
"name": "clientBulkWrite",
"object": "client",
"arguments": {
"models": [
{
"insertOne": {
"namespace": "crud_id.type_tests",
"document": {
"_id": null
}
}
}
]
}
},
{
"name": "countDocuments",
"object": "collection",
"arguments": {
"filter": {
"_id": {
"$type": "null"
}
}
},
"expectResult": 1
}
]
}
]
}
97 changes: 97 additions & 0 deletions src/test/spec/json/crud/unified/create-null-ids.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
description: create-null-ids
schemaVersion: '1.0'

createEntities:
- client:
id: client
observeEvents:
- commandStartedEvent
- database:
id: &database database
client: client
databaseName: crud_id
- collection:
id: &collection collection
database: *database
collectionName: type_tests

initialData:
- collectionName: type_tests
databaseName: crud_id
documents: []

tests:

- description: inserting _id with type null via insertOne
operations:
- name: insertOne
object: *collection
arguments: {document: &null_id {_id: null}}
# We use countDocuments with a $type query to verify the insert of the correct BSON type
# this is to avoid client side type conversions (potentially common: undefined -> null)
- name: countDocuments
object: *collection
arguments: {filter: &null_id_filter {_id: {$type: 'null'}}}
expectResult: 1

- description: inserting _id with type null via insertMany
operations:
- name: insertMany
object: *collection
arguments: {documents: [*null_id]}
- name: countDocuments
object: *collection
arguments: {filter: *null_id_filter}
expectResult: 1

- description: inserting _id with type null via updateOne
operations:
- name: updateOne
object: *collection
arguments: {filter: *null_id, update: {$unset: {a: ''}}, upsert: true}
- name: countDocuments
object: *collection
arguments: {filter: *null_id_filter}
expectResult: 1

- description: inserting _id with type null via updateMany
operations:
- name: updateMany
object: *collection
arguments: {filter: *null_id, update: {$unset: {a: ''}}, upsert: true}
- name: countDocuments
object: *collection
arguments: {filter: *null_id_filter}
expectResult: 1

- description: inserting _id with type null via replaceOne
operations:
- name: replaceOne
object: *collection
arguments: {filter: {}, replacement: *null_id, upsert: true}
- name: countDocuments
object: *collection
arguments: {filter: *null_id_filter}
expectResult: 1

- description: inserting _id with type null via bulkWrite
operations:
- name: bulkWrite
object: *collection
arguments: {requests: [{insertOne: {document: *null_id}}]}
- name: countDocuments
object: *collection
arguments: {filter: *null_id_filter}
expectResult: 1

- description: inserting _id with type null via clientBulkWrite
runOnRequirements:
- minServerVersion: '8.0'
operations:
- name: clientBulkWrite
object: client
arguments: {models: [{insertOne: {namespace: crud_id.type_tests, document: *null_id}}]}
- name: countDocuments
object: *collection
arguments: {filter: *null_id_filter}
expectResult: 1

0 comments on commit 288d796

Please sign in to comment.