-
Notifications
You must be signed in to change notification settings - Fork 895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GODRIVER-2388 Improved Bulk Write API. #1884
base: master
Are you sure you want to change the base?
Changes from 7 commits
1309416
4d88edf
d10eff2
3489ac8
acca80b
fc91428
ce3ed92
4f9c841
89947bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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, | ||||||
"expected 2 calls to BypassAutoEncryption, got %v", cc.numBypassAutoEncryptionCalls) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: Update error message to match updated assertion.
Suggested change
|
||||||
}) | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: We should separate test functions as much as possible because it makes the code easier to read and the test easier to run. Consider splitting these two E.g. func TestClient_BulkWrite(t *testing.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) { | ||
|
There was a problem hiding this comment.
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.