Skip to content

Commit

Permalink
Remove unified test for UpdateMany.
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Sep 10, 2024
1 parent 47e73f5 commit eb158b4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 211 deletions.
11 changes: 11 additions & 0 deletions mongo/integration/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}}
Expand Down
23 changes: 0 additions & 23 deletions mongo/integration/crud_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
132 changes: 0 additions & 132 deletions testdata/crud/unified/updateMany-sort.json

This file was deleted.

56 changes: 0 additions & 56 deletions testdata/crud/unified/updateMany-sort.yml

This file was deleted.

0 comments on commit eb158b4

Please sign in to comment.