Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/driverutil/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ const (
ListIndexesOp = "listIndexes" // ListIndexesOp is the name for listing indexes
ListDatabasesOp = "listDatabases" // ListDatabasesOp is the name for listing databases
UpdateOp = "update" // UpdateOp is the name for updating
BulkWriteOp = "bulkWrite" // BulkWriteOp is the name for client-level bulk write
)
2 changes: 1 addition & 1 deletion internal/integration/client_side_encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func TestClientSideEncryptionCustomCrypt(t *testing.T) {
"expected 0 calls to DecryptExplicit, got %v", cc.numDecryptExplicitCalls)
assert.Equal(mt, cc.numCloseCalls, 0,
"expected 0 calls to Close, got %v", cc.numCloseCalls)
assert.Equal(mt, cc.numBypassAutoEncryptionCalls, 2,
assert.Equal(mt, cc.numBypassAutoEncryptionCalls, 1,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only call it once after the operation.go refactoring.

"expected 2 calls to BypassAutoEncryption, got %v", cc.numBypassAutoEncryptionCalls)
})
}
Expand Down
72 changes: 72 additions & 0 deletions internal/integration/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
"go.mongodb.org/mongo-driver/v2/mongo/writeconcern"
"go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/wiremessage"
Expand Down Expand Up @@ -718,6 +719,77 @@ func TestClient(t *testing.T) {
})
}
})
mtBulkWriteOpts := mtest.NewOptions().MinServerVersion("8.0").AtlasDataLake(false).ClientType(mtest.Pinned)
mt.RunOpts("bulk write with nil filter", mtBulkWriteOpts, func(mt *mtest.T) {
mt.Parallel()

testCases := []struct {
name string
models *mongo.ClientWriteModels
}{
{
name: "DeleteOne",
models: (&mongo.ClientWriteModels{}).AppendDeleteOne("foo", "bar", mongo.NewClientDeleteOneModel()),
},
{
name: "DeleteMany",
models: (&mongo.ClientWriteModels{}).AppendDeleteMany("foo", "bar", mongo.NewClientDeleteManyModel()),
},
{
name: "UpdateOne",
models: (&mongo.ClientWriteModels{}).AppendUpdateOne("foo", "bar", mongo.NewClientUpdateOneModel()),
},
{
name: "UpdateMany",
models: (&mongo.ClientWriteModels{}).AppendUpdateMany("foo", "bar", mongo.NewClientUpdateManyModel()),
},
}
for _, tc := range testCases {
tc := tc

mt.Run(tc.name, func(mt *mtest.T) {
mt.Parallel()

_, err := mt.Client.BulkWrite(context.Background(), tc.models)
require.ErrorContains(mt, err, "filter is required")
})
}
})
mt.RunOpts("bulk write with write concern", mtBulkWriteOpts, func(mt *mtest.T) {
mt.Parallel()

testCases := []struct {
name string
opts *options.ClientBulkWriteOptionsBuilder
want bool
}{
{
name: "unacknowledged",
opts: options.ClientBulkWrite().SetWriteConcern(writeconcern.Unacknowledged()).SetOrdered(false),
want: false,
},
{
name: "acknowledged",
want: true,
},
}
for _, tc := range testCases {
tc := tc

mt.Run(tc.name, func(mt *mtest.T) {
mt.Parallel()

var models *mongo.ClientWriteModels

insertOneModel := mongo.NewClientInsertOneModel().SetDocument(bson.D{{"x", 1}})
models = (&mongo.ClientWriteModels{}).AppendInsertOne("foo", "bar", insertOneModel)
res, err := mt.Client.BulkWrite(context.Background(), models, tc.opts)
require.NoError(mt, err, "BulkWrite error: %v", err)
require.NotNil(mt, res, "expected a ClientBulkWriteResult")
assert.Equal(mt, res.Acknowledged, tc.want, "expected Acknowledged: %v, got: %v", tc.want, res.Acknowledged)
})
}
})
}

func TestClient_BSONOptions(t *testing.T) {
Expand Down
35 changes: 35 additions & 0 deletions internal/integration/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,41 @@ func TestCollection(t *testing.T) {
})
}
})
mt.Run("error on nil filter", func(mt *mtest.T) {
mt.Parallel()

testCases := []struct {
name string
model mongo.WriteModel
}{
{
name: "DeleteOne",
model: mongo.NewDeleteOneModel(),
},
{
name: "DeleteMany",
model: mongo.NewDeleteManyModel(),
},
{
name: "UpdateOne",
model: mongo.NewUpdateOneModel().SetUpdate(bson.D{{"$set", bson.D{{"x", 1}}}}),
},
{
name: "UpdateMany",
model: mongo.NewUpdateManyModel().SetUpdate(bson.D{{"$set", bson.D{{"x", 1}}}}),
},
}
for _, tc := range testCases {
tc := tc

mt.Run(tc.name, func(mt *mtest.T) {
mt.Parallel()

_, err := mt.Coll.BulkWrite(context.Background(), []mongo.WriteModel{tc.model})
assert.ErrorContains(mt, err, "filter is required")
})
}
})
mt.Run("correct model in errors", func(mt *mtest.T) {
models := []mongo.WriteModel{
mongo.NewUpdateOneModel().SetFilter(bson.M{}).SetUpdate(bson.M{
Expand Down
Loading
Loading