...

Text file src/go.mongodb.org/mongo-driver/testdata/command-monitoring/insertOne.yml

Documentation: go.mongodb.org/mongo-driver/testdata/command-monitoring

     1description: "insertOne"
     2
     3schemaVersion: "1.0"
     4
     5createEntities:
     6  - client:
     7      id: &client client
     8      observeEvents:
     9        - commandStartedEvent
    10        - commandSucceededEvent
    11        - commandFailedEvent
    12  - database:
    13      id: &database database
    14      client: *client
    15      databaseName: &databaseName command-monitoring-tests
    16  - collection:
    17      id: &collection collection
    18      database: *database
    19      collectionName: &collectionName test
    20
    21initialData:
    22  - collectionName: *collectionName
    23    databaseName: *databaseName
    24    documents:
    25      - { _id: 1, x: 11 }
    26
    27tests:
    28  - description: "A successful insertOne"
    29    operations:
    30      - name: insertOne
    31        object: *collection
    32        arguments:
    33          document: { _id: 2, x: 22 }
    34    expectEvents:
    35      - client: *client
    36        events:
    37          - commandStartedEvent:
    38              command:
    39                insert: *collectionName
    40                documents:
    41                  - { _id: 2, x: 22 }
    42                ordered: true
    43              commandName: insert
    44              databaseName: *databaseName
    45          - commandSucceededEvent:
    46              reply: { ok: 1, n: 1 }
    47              commandName: insert
    48
    49  - description: "A successful insertOne with write errors"
    50    operations:
    51      - name: insertOne
    52        object: *collection
    53        arguments:
    54          document: { _id: 1, x: 11 }
    55        expectError:
    56          isClientError: false
    57    expectEvents:
    58      - client: *client
    59        events:
    60          - commandStartedEvent:
    61              command:
    62                insert: *collectionName
    63                documents:
    64                  - { _id: 1, x: 11 }
    65                ordered: true
    66              commandName: insert
    67              databaseName: *databaseName
    68          - commandSucceededEvent:
    69              reply:
    70                ok: 1
    71                n: 0
    72                # The legacy version of this test included an assertion that writeErrors contained a single document
    73                # with index=0, a "code" value, and a non-empty "errmsg". However, writeErrors can contain extra fields
    74                # beyond these, and the unified format currently does not permit allowing extra fields in sub-documents,
    75                # so those assertions are not present here.
    76                writeErrors: { $$type: array }
    77              commandName: insert

View as plain text