...

Text file src/go.mongodb.org/mongo-driver/testdata/crud/unified/findOneAndUpdate-errorResponse.yml

Documentation: go.mongodb.org/mongo-driver/testdata/crud/unified

     1description: "findOneAndUpdate-errorResponse"
     2
     3schemaVersion: "1.12"
     4
     5createEntities:
     6  - client:
     7      id: &client0 client0
     8  - database:
     9      id: &database0 database0
    10      client: *client0
    11      databaseName: &database0Name crud-tests
    12  - collection:
    13      id: &collection0 collection0
    14      database: *database0
    15      collectionName: &collection0Name test
    16
    17initialData: &initialData
    18  - collectionName: *collection0Name
    19    databaseName: *database0Name
    20    documents:
    21      - { _id: 1, x: "foo" }
    22
    23tests:
    24  - description: "findOneAndUpdate DuplicateKey error is accessible"
    25    runOnRequirements:
    26      - minServerVersion: "4.2" # SERVER-37124
    27    operations:
    28      - name: createIndex
    29        object: *collection0
    30        arguments:
    31          keys: { x: 1 }
    32          unique: true
    33      - name: findOneAndUpdate
    34        object: *collection0
    35        arguments:
    36          filter: { _id: 2 }
    37          update: { $set: { x: "foo" } }
    38          upsert: true
    39        expectError:
    40          errorCode: 11000 # DuplicateKey
    41          errorResponse:
    42            keyPattern: { x: 1 }
    43            keyValue: { x: "foo" }
    44
    45  - description: "findOneAndUpdate document validation errInfo is accessible"
    46    runOnRequirements:
    47      - minServerVersion: "5.0"
    48    operations:
    49      - name: modifyCollection
    50        object: *database0
    51        arguments:
    52          collection: *collection0Name
    53          validator:
    54            x: { $type: "string" }
    55      - name: findOneAndUpdate
    56        object: *collection0
    57        arguments:
    58          filter: { _id: 1 }
    59          update: { $set: { x: 1 } }
    60        expectError:
    61          errorCode: 121 # DocumentValidationFailure
    62          errorResponse:
    63            # Avoid asserting the exact contents of errInfo as it may vary by
    64            # server version. Likewise, this is why drivers do not model the
    65            # document. The following is sufficient to test that validation
    66            # details are accessible. See SERVER-20547 for more context.
    67            errInfo:
    68              failingDocumentId: 1
    69              details: { $$type: "object" }

View as plain text