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 1bf0533
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 214 deletions.
2 changes: 1 addition & 1 deletion internal/test/compilecheck/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ require (
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
4 changes: 2 additions & 2 deletions internal/test/compilecheck/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
15 changes: 15 additions & 0 deletions mongo/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package mongo

import (
"context"
"errors"
"testing"

Expand Down Expand Up @@ -128,6 +129,20 @@ func TestCollection(t *testing.T) {
err = coll.FindOneAndUpdate(bgCtx, doc, update).Err()
assert.Equal(t, ErrClientDisconnected, err, "expected error %v, got %v", ErrClientDisconnected, err)
})
t.Run("error on UpdateMany with sort", func(t *testing.T) {
client := setupClient()
err := client.Connect(bgCtx)
defer func() { _ = client.Disconnect(bgCtx) }()
assert.NoError(t, err, "unexpected connecting error %v", err)
coll := client.Database(testDbName).Collection("foo")
doc := bson.D{}
update := bson.D{{"$inc", bson.D{{"x", 1}}}}

_, err = coll.UpdateMany(context.Background(), doc, update, &options.UpdateOptions{Sort: bson.D{{"_id", -1}}})
// The error is either "Cannot specify sort with multi=true" for servers >= 8.0,
// or "BSON field 'update.updates.sort' is an unknown field." for servers < 8.0.
assert.ErrorContains(t, err, "sort", "expected error on UpdateMany with sort")
})
t.Run("database accessor", func(t *testing.T) {
coll := setupColl("bar")
dbName := coll.Database().Name()
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 1bf0533

Please sign in to comment.