Skip to content

Commit

Permalink
Align client bulk write API with legacy bulk write.
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Dec 18, 2024
1 parent 4f9c841 commit 91dabcd
Show file tree
Hide file tree
Showing 12 changed files with 423 additions and 368 deletions.
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 @@ -395,7 +395,7 @@ func TestClientSideEncryptionCustomCrypt(t *testing.T) {
assert.Equal(mt, cc.numCloseCalls, 0,
"expected 0 calls to Close, got %v", cc.numCloseCalls)
assert.Equal(mt, cc.numBypassAutoEncryptionCalls, 1,
"expected 2 calls to BypassAutoEncryption, got %v", cc.numBypassAutoEncryptionCalls)
"expected 1 calls to BypassAutoEncryption, got %v", cc.numBypassAutoEncryptionCalls)
})
}

Expand Down
46 changes: 32 additions & 14 deletions internal/integration/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,23 +725,39 @@ func TestClient(t *testing.T) {

testCases := []struct {
name string
models *mongo.ClientWriteModels
writes []mongo.ClientBulkWrite
}{
{
name: "DeleteOne",
models: (&mongo.ClientWriteModels{}).AppendDeleteOne("foo", "bar", mongo.NewClientDeleteOneModel()),
name: "DeleteOne",
writes: []mongo.ClientBulkWrite{{
Database: "foo",
Collection: "bar",
Model: mongo.NewClientDeleteOneModel(),
}},
},
{
name: "DeleteMany",
models: (&mongo.ClientWriteModels{}).AppendDeleteMany("foo", "bar", mongo.NewClientDeleteManyModel()),
name: "DeleteMany",
writes: []mongo.ClientBulkWrite{{
Database: "foo",
Collection: "bar",
Model: mongo.NewClientDeleteManyModel(),
}},
},
{
name: "UpdateOne",
models: (&mongo.ClientWriteModels{}).AppendUpdateOne("foo", "bar", mongo.NewClientUpdateOneModel()),
name: "UpdateOne",
writes: []mongo.ClientBulkWrite{{
Database: "foo",
Collection: "bar",
Model: mongo.NewClientUpdateOneModel(),
}},
},
{
name: "UpdateMany",
models: (&mongo.ClientWriteModels{}).AppendUpdateMany("foo", "bar", mongo.NewClientUpdateManyModel()),
name: "UpdateMany",
writes: []mongo.ClientBulkWrite{{
Database: "foo",
Collection: "bar",
Model: mongo.NewClientUpdateManyModel(),
}},
},
}
for _, tc := range testCases {
Expand All @@ -750,7 +766,7 @@ func TestClient(t *testing.T) {
mt.Run(tc.name, func(mt *mtest.T) {
mt.Parallel()

_, err := mt.Client.BulkWrite(context.Background(), tc.models)
_, err := mt.Client.BulkWrite(context.Background(), tc.writes)
require.ErrorContains(mt, err, "filter is required")
})
}
Expand Down Expand Up @@ -779,11 +795,13 @@ func TestClient(t *testing.T) {
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)
writes := []mongo.ClientBulkWrite{{
Database: "foo",
Collection: "bar",
Model: insertOneModel,
}}
res, err := mt.Client.BulkWrite(context.Background(), writes, 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)
Expand Down
Loading

0 comments on commit 91dabcd

Please sign in to comment.