From eb158b4153b67c1de308cb74cc53ff079c7fd2b5 Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Tue, 10 Sep 2024 11:10:05 -0400 Subject: [PATCH] Remove unified test for UpdateMany. --- mongo/integration/collection_test.go | 11 ++ mongo/integration/crud_helpers_test.go | 23 ---- testdata/crud/unified/updateMany-sort.json | 132 --------------------- testdata/crud/unified/updateMany-sort.yml | 56 --------- 4 files changed, 11 insertions(+), 211 deletions(-) delete mode 100644 testdata/crud/unified/updateMany-sort.json delete mode 100644 testdata/crud/unified/updateMany-sort.yml diff --git a/mongo/integration/collection_test.go b/mongo/integration/collection_test.go index 15c0e9324c..423f94624c 100644 --- a/mongo/integration/collection_test.go +++ b/mongo/integration/collection_test.go @@ -640,6 +640,17 @@ func TestCollection(t *testing.T) { assert.Equal(mt, int64(0), res.ModifiedCount, "expected modified count 0, got %v", res.ModifiedCount) assert.NotNil(mt, res.UpsertedID, "expected upserted ID, got nil") }) + // Require 8.0 servers for sort support. + mt.RunOpts("error with sort", mtest.NewOptions().MinServerVersion("8.0"), func(mt *mtest.T) { + filter := bson.D{{"x", bson.D{{"$gte", 3}}}} + update := bson.D{{"$inc", bson.D{{"x", 1}}}} + + _, err := mt.Coll.UpdateMany(context.Background(), + filter, update, + &options.UpdateOptions{Sort: bson.D{{"_id", -1}}}, + ) + assert.EqualError(t, err, "Cannot specify sort with multi=true", "expected an error on UpdateMany with sort") + }) mt.Run("write error", func(mt *mtest.T) { filter := bson.D{{"_id", "foo"}} update := bson.D{{"$set", bson.D{{"_id", 3.14159}}}} diff --git a/mongo/integration/crud_helpers_test.go b/mongo/integration/crud_helpers_test.go index d7eb7c833a..3344ac297b 100644 --- a/mongo/integration/crud_helpers_test.go +++ b/mongo/integration/crud_helpers_test.go @@ -80,20 +80,6 @@ func createHint(mt *mtest.T, val bson.RawValue) interface{} { return hint } -// create a sort document from a bson.RawValue -func createSort(mt *mtest.T, val bson.RawValue) interface{} { - mt.Helper() - - var sort interface{} - switch val.Type { - case bsontype.EmbeddedDocument: - sort = val.Document() - default: - mt.Fatalf("unrecognized sort value type: %s\n", val.Type) - } - return sort -} - // returns true if err is a mongo.CommandError containing a code that is expected from a killAllSessions command. func isExpectedKillAllSessionsError(err error) bool { cmdErr, ok := err.(mongo.CommandError) @@ -904,8 +890,6 @@ func executeUpdateOne(mt *mtest.T, sess mongo.Session, args bson.Raw) (*mongo.Up opts = opts.SetCollation(createCollation(mt, val.Document())) case "hint": opts = opts.SetHint(createHint(mt, val)) - case "sort": - opts = opts.SetSort(createSort(mt, val)) case "session": default: mt.Fatalf("unrecognized updateOne option: %v", key) @@ -954,8 +938,6 @@ func executeUpdateMany(mt *mtest.T, sess mongo.Session, args bson.Raw) (*mongo.U opts = opts.SetCollation(createCollation(mt, val.Document())) case "hint": opts = opts.SetHint(createHint(mt, val)) - case "sort": - opts = opts.SetSort(createSort(mt, val)) case "session": default: mt.Fatalf("unrecognized updateMany option: %v", key) @@ -1000,8 +982,6 @@ func executeReplaceOne(mt *mtest.T, sess mongo.Session, args bson.Raw) (*mongo.U opts = opts.SetCollation(createCollation(mt, val.Document())) case "hint": opts = opts.SetHint(createHint(mt, val)) - case "sort": - opts = opts.SetSort(createSort(mt, val)) case "session": default: mt.Fatalf("unrecognized replaceOne option: %v", key) @@ -1142,9 +1122,6 @@ func createBulkWriteModel(mt *mtest.T, rawModel bson.Raw) mongo.WriteModel { if hintVal, err := args.LookupErr("hint"); err == nil { uom.SetHint(createHint(mt, hintVal)) } - if sortVal, err := args.LookupErr("sort"); err == nil { - uom.SetSort(createSort(mt, sortVal)) - } if uom.Upsert == nil { uom.SetUpsert(false) } diff --git a/testdata/crud/unified/updateMany-sort.json b/testdata/crud/unified/updateMany-sort.json deleted file mode 100644 index d54fba4ba6..0000000000 --- a/testdata/crud/unified/updateMany-sort.json +++ /dev/null @@ -1,132 +0,0 @@ -{ - "description": "updateMany-sort", - "schemaVersion": "1.0", - "createEntities": [ - { - "client": { - "id": "client0", - "observeEvents": [ - "commandStartedEvent" - ] - } - }, - { - "database": { - "id": "database0", - "client": "client0", - "databaseName": "crud-tests" - } - }, - { - "collection": { - "id": "collection0", - "database": "database0", - "collectionName": "coll0" - } - } - ], - "initialData": [ - { - "collectionName": "coll0", - "databaseName": "crud-tests", - "documents": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - }, - { - "_id": 3, - "x": 33 - } - ] - } - ], - "tests": [ - { - "description": "UpdateMany with sort option unsupported", - "operations": [ - { - "name": "updateMany", - "object": "collection0", - "arguments": { - "filter": { - "_id": { - "$gt": 1 - } - }, - "sort": { - "_id": -1 - }, - "update": { - "$inc": { - "x": 1 - } - } - }, - "expectError": { - "isClientError": false - } - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "update": "coll0", - "updates": [ - { - "q": { - "_id": { - "$gt": 1 - } - }, - "u": { - "$inc": { - "x": 1 - } - }, - "sort": { - "_id": -1 - }, - "multi": true, - "upsert": { - "$$unsetOrMatches": false - } - } - ] - } - } - } - ] - } - ], - "outcome": [ - { - "collectionName": "coll0", - "databaseName": "crud-tests", - "documents": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - }, - { - "_id": 3, - "x": 33 - } - ] - } - ] - } - ] -} diff --git a/testdata/crud/unified/updateMany-sort.yml b/testdata/crud/unified/updateMany-sort.yml deleted file mode 100644 index eb576e2b79..0000000000 --- a/testdata/crud/unified/updateMany-sort.yml +++ /dev/null @@ -1,56 +0,0 @@ -description: updateMany-sort - -schemaVersion: "1.0" - -createEntities: - - client: - id: client0 - observeEvents: - - commandStartedEvent - - database: - id: database0 - client: client0 - databaseName: crud-tests - - collection: - id: collection0 - database: database0 - collectionName: coll0 - -initialData: - - collectionName: coll0 - databaseName: crud-tests - documents: - - { _id: 1, x: 11 } - - { _id: 2, x: 22 } - - { _id: 3, x: 33 } - -tests: - - description: UpdateMany with sort option unsupported - operations: - - name: updateMany - object: collection0 - arguments: - filter: { _id: { $gt: 1 } } - sort: { _id: -1 } - update: { $inc: { x: 1 } } - expectError: - isClientError: false - expectEvents: - - client: client0 - events: - - commandStartedEvent: - command: - update: coll0 - updates: - - q: { _id: { $gt: 1 } } - u: { $inc: { x: 1 } } - sort: { _id: -1 } - multi: true - upsert: { $$unsetOrMatches: false } - outcome: - - collectionName: coll0 - databaseName: crud-tests - documents: - - { _id: 1, x: 11 } - - { _id: 2, x: 22 } - - { _id: 3, x: 33 }