Skip to content

Commit 9ad41a1

Browse files
authored
DRIVERS-3013: List more examples of root-level documents (#1694)
1 parent b90695b commit 9ad41a1

File tree

1 file changed

+66
-18
lines changed

1 file changed

+66
-18
lines changed

source/unified-test-format/unified-test-format.md

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,8 @@ The structure of this object is as follows:
10201020
The structure of this object is as follows:
10211021

10221022
- `command`: Optional document. A value corresponding to the expected command document. Test runners MUST follow the
1023-
rules in [Evaluating Matches](#evaluating-matches) when processing this assertion.
1023+
rules in [Evaluating Matches](#evaluating-matches) when processing this assertion and match the value as a
1024+
root-level document.
10241025
- `commandName`: Optional string. Test runners MUST assert that the command name matches this value.
10251026
- `databaseName`: Optional string. Test runners MUST assert that the database name matches this value. The YAML file
10261027
SHOULD use an [alias node](https://yaml.org/spec/1.2/spec.html#id2786196) for this value (e.g.
@@ -1036,7 +1037,8 @@ The structure of this object is as follows:
10361037
The structure of this object is as follows:
10371038

10381039
- `reply`: Optional document. A value corresponding to the expected reply document. Test runners MUST follow the rules
1039-
in [Evaluating Matches](#evaluating-matches) when processing this assertion.
1040+
in [Evaluating Matches](#evaluating-matches) when processing this assertion and match the value as a root-level
1041+
document.
10401042
- `commandName`: Optional string. Test runners MUST assert that the command name matches this value.
10411043
- `databaseName`: Optional string. Test runners MUST assert that the database name matches this value. The YAML file
10421044
SHOULD use an [alias node](https://yaml.org/spec/1.2/spec.html#id2786196) for this value (e.g.
@@ -1663,6 +1665,10 @@ below.
16631665
When executing an `aggregate` operation, the test runner MUST fully iterate the result. This will ensure consistent
16641666
behavior between drivers that eagerly create a server-side cursor and those that do so lazily when iteration begins.
16651667

1668+
When evaluating the iterated result for [expectResult](#operation_expectResult), the number of actual and expected
1669+
documents MUST be equal and each document value within the `expectResult` array MUST be matched as a root-level document
1670+
(for [Evaluating Matches](#evaluating-matches)).
1671+
16661672
#### bulkWrite
16671673

16681674
These considerations only apply to the `MongoCollection.bulkWrite` method. See [clientBulkWrite](#clientbulkwrite) for
@@ -1765,12 +1771,19 @@ This operation proxies the collection's `dropSearchIndex` helper with the same a
17651771
When executing a `find` operation, the test runner MUST fully iterate the result. This will ensure consistent behavior
17661772
between drivers that eagerly create a server-side cursor and those that do so lazily when iteration begins.
17671773

1774+
When evaluating the iterated result for [expectResult](#operation_expectResult), the number of actual and expected
1775+
documents MUST be equal and each document value within the `expectResult` array MUST be matched as a root-level document
1776+
(for [Evaluating Matches](#evaluating-matches)).
1777+
17681778
#### findOneAndReplace and findOneAndUpdate
17691779

17701780
The `returnDocument` option for `findOneAndReplace` and `findOneAndUpdate` is documented as an enum with possible values
17711781
"Before" and "After". Test files SHOULD express `returnDocument` as a string and test runners MUST raise an error if its
17721782
value does not case-insensitively match either enum value.
17731783

1784+
When evaluating the result for [expectResult](#operation_expectResult), the document MUST be matched as a root-level
1785+
document (for [Evaluating Matches](#evaluating-matches)).
1786+
17741787
#### insertMany
17751788

17761789
The CRUD spec documents `insertMany` as returning a BulkWriteResult. Because the `insertedIds` field of BulkWriteResult
@@ -1897,7 +1910,8 @@ first position (e.g. `rewind` in PHP).
18971910
#### iterateUntilDocumentOrError
18981911

18991912
Iterates the cursor until either a single document is returned or an error is raised. This operation takes no arguments.
1900-
If [expectResult](#operation_expectResult) is specified, it SHOULD be a single document.
1913+
If [expectResult](#operation_expectResult) is specified, it SHOULD be a single document and MUST be matched as a
1914+
root-level document according to the rules in [Evaluating Matches](#evaluating-matches).
19011915

19021916
Some specification sections (e.g.
19031917
[Iterating the Change Stream](../change-streams/tests/README.md#iterating-the-change-stream)) caution drivers that
@@ -2709,15 +2723,7 @@ actual value of `1.0` (e.g. `ok` field in a server response) but would not match
27092723
#### Allowing Extra Fields in Root-level Documents
27102724

27112725
When matching root-level documents, test runners MUST permit the actual document to contain additional fields not
2712-
present in the expected document. Examples of root-level documents include, but are not limited to:
2713-
2714-
- `command` for [CommandStartedEvent](#expectedEvent_commandStartedEvent)
2715-
- `reply` for [CommandSucceededEvent](#expectedEvent_commandSucceededEvent)
2716-
- [expectResult](#operation_expectResult) for `findOneAndUpdate` [Collection Operations](#collection-operations)
2717-
- [expectResult](#operation_expectResult) for [iterateUntilDocumentOrError](#iterateuntildocumentorerror)
2718-
- [expectedError_errorResponse](#expectedError_errorResponse)
2719-
- each array element in [expectResult](#operation_expectResult) for [find](#find) or
2720-
[collection_aggregate](#collection_aggregate) [Collection Operations](#collection-operations)
2726+
present in the expected document.
27212727

27222728
For example, the following documents match:
27232729

@@ -2745,15 +2751,47 @@ is not always feasible or relevant for a test to exhaustively specify all fields
27452751
time in `command` for [CommandStartedEvent](#expectedEvent_commandStartedEvent)).
27462752

27472753
When the expected value is an array, test runners MUST differentiate between an array of values, which may be documents,
2748-
(e.g. `distinct`) and an array of root-level documents (e.g. `find`, `aggregate`). For example, the following array of
2749-
documents would not match if returned by `distinct`, but would match if returned via `find` (after iterating the
2750-
cursor):
2754+
(e.g. `distinct`) and an array of root-level documents derived from an iterable result (e.g. `find`, `aggregate`). For
2755+
example, the following array of documents would not match if returned by `distinct`, but would match if returned via
2756+
`find` (after iterating the cursor):
27512757

27522758
```yaml
27532759
expected: [ { x: 1 }, { x: 2 } ]
27542760
actual: [ { x: 1, y: 1 }, { x: 2, y: 2 } ]
27552761
```
27562762

2763+
##### Examples of Root-level Documents
2764+
2765+
Contexts where one might encounter a root-level document include:
2766+
2767+
- `command` for [CommandStartedEvent](#expectedEvent_commandStartedEvent)
2768+
2769+
- `reply` for [CommandSucceededEvent](#expectedEvent_commandSucceededEvent)
2770+
2771+
- [expectResult](#operation_expectResult) for operations that return a document. Operations include:
2772+
2773+
- findOneAndDelete, [findOneAndReplace](#findoneandreplace-and-findoneandupdate), and
2774+
[findOneAndUpdate](#findoneandreplace-and-findoneandupdate)
2775+
- [iterateUntilDocumentOrError](#iterateuntildocumentorerror)
2776+
- [iterateOnce](#iterateonce)
2777+
2778+
- [expectResult](#operation_expectResult) array elements for operations that return an iterable of documents. Operations
2779+
include:
2780+
2781+
- [aggregate](#aggregate)
2782+
- [find](#find))
2783+
- [listCollections](#listcollections), listDatabases, and listIndexes
2784+
- [listSearchIndexes](#listsearchindexes)
2785+
- [runCursorCommand](#runcursorcommand)
2786+
2787+
- [errorResponse](#expectedError_errorResponse) for [expectedError](#expectederror)
2788+
2789+
- `writeErrors` object values for [expectedError](#expectederror)
2790+
2791+
- `writeConcernErrors` array elements for [expectedError](#expectederror)
2792+
2793+
- `data` for [expectedLogMessage](#expectedlogmessage)
2794+
27572795
#### Document Key Order Variation
27582796

27592797
When matching documents, test runners MUST NOT require keys in the expected and actual document to appear in the same
@@ -2861,6 +2899,8 @@ the test runner MUST fetch that entity and assert that the actual value matches
28612899
[Evaluating Matches](#evaluating-matches); otherwise, the test runner MUST raise an error for an undefined or mistyped
28622900
entity. The YAML file SHOULD use an [alias node](https://yaml.org/spec/1.2/spec.html#id2786196) for the entity name.
28632901

2902+
This operator does not influence whether or not an actual document value is considered a root-level document.
2903+
28642904
This operator is primarily used to assert identifiers for uploaded GridFS files.
28652905

28662906
An example of this operator follows:
@@ -2911,6 +2951,8 @@ excluding an array element because
29112951
MUST assert that the actual value either does not exist or matches the expected value. Matching the expected value MUST
29122952
use the standard rules in [Evaluating Matches](#evaluating-matches), which means that it may contain special operators.
29132953

2954+
This operator does not influence whether or not an actual document value is considered a root-level document.
2955+
29142956
This operator is primarily used to assert driver-optional fields from the CRUD spec (e.g. `insertedId` for
29152957
InsertOneResult, `writeResult` for BulkWriteException).
29162958

@@ -2980,9 +3022,13 @@ Syntax:
29803022

29813023
This operator may be used anywhere a matched value is expected (including [expectResult](#operation_expectResult)) and
29823024
the actual value is an extended JSON string. The test runner MUST parse the actual value into a BSON document and match
2983-
it against the expected value. Matching the expected value MUST use the standard rules in
2984-
[Evaluating Matches](#evaluating-matches), which means that it may contain special operators. This operator is primarily
2985-
used to assert on extended JSON commands and command replies included in log messages.
3025+
it against the expected value.
3026+
3027+
Matching the expected value MUST use the standard rules in [Evaluating Matches](#evaluating-matches), which means that
3028+
it may contain special operators. The actual value MUST NOT be considered a root-level document (i.e. extra fields are
3029+
not permitted); however, [$$matchAsRoot](#matchasroot) may be used to change that behavior.
3030+
3031+
This operator is primarily used to assert on extended JSON commands and command replies included in log messages.
29863032

29873033
##### $$matchAsRoot
29883034

@@ -3505,6 +3551,8 @@ other specs *and* collating spec changes developed in parallel or during the sam
35053551

35063552
## Changelog
35073553

3554+
- 2024-10-29: List more examples of root-level documents
3555+
35083556
- 2024-10-24: Document `namespace` option for `failCommand` fail point.
35093557

35103558
- 2024-09-18: Note that `failCommand` `appName` option was backported

0 commit comments

Comments
 (0)