Skip to content

CSHARP-5372: Sync tests for null insert/upsert _id values #1666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
253 changes: 253 additions & 0 deletions specifications/crud/tests/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 specifications/crud/tests/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