Skip to content
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

Return command error from findAndModify #2646

Merged
merged 17 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use compat when we can
  • Loading branch information
chilagrow committed May 19, 2023
commit 748d3af1635413b2eb6b6b078e7e4b399ee20046
11 changes: 9 additions & 2 deletions integration/update_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type updateCompatTestCase struct {
update bson.D // required if replace is nil
replace bson.D // required if update is nil
filter bson.D // defaults to bson.D{{"_id", id}}
updateOpts *options.UpdateOptions // defaults to nil
replaceOpts *options.ReplaceOptions // defaults to nil
resultType compatTestCaseResultType // defaults to nonEmptyResult
providers []shareddata.Provider // defaults to shareddata.AllProviders()
Expand Down Expand Up @@ -109,8 +110,8 @@ func testUpdateCompat(t *testing.T, testCases map[string]updateCompatTestCase) {
// TODO replace with UpdateMany/ReplaceMany
// https://github.com/FerretDB/FerretDB/issues/1507
if update != nil {
targetUpdateRes, targetErr = targetCollection.UpdateOne(ctx, filter, update)
compatUpdateRes, compatErr = compatCollection.UpdateOne(ctx, filter, update)
targetUpdateRes, targetErr = targetCollection.UpdateOne(ctx, filter, update, tc.updateOpts)
compatUpdateRes, compatErr = compatCollection.UpdateOne(ctx, filter, update, tc.updateOpts)
} else {
targetUpdateRes, targetErr = targetCollection.ReplaceOne(ctx, filter, replace, tc.replaceOpts)
compatUpdateRes, compatErr = compatCollection.ReplaceOne(ctx, filter, replace, tc.replaceOpts)
Expand Down Expand Up @@ -448,6 +449,12 @@ func TestUpdateCompat(t *testing.T) {
replaceOpts: &options.ReplaceOptions{Upsert: pointer.ToBool(true)},
resultType: emptyResult,
},
"UpdateNonExistentUpsert": {
filter: bson.D{{"_id", "non-existent"}},
update: bson.D{{"$set", bson.D{{"v", int32(42)}}}},
updateOpts: &options.UpdateOptions{Upsert: pointer.ToBool(true)},
resultType: emptyResult,
},
}

testUpdateCompat(t, testCases)
Expand Down
16 changes: 0 additions & 16 deletions integration/update_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ import (
"math"
"testing"

"github.com/AlekSi/pointer"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"

"github.com/FerretDB/FerretDB/integration/setup"
"github.com/FerretDB/FerretDB/integration/shareddata"
Expand All @@ -36,7 +34,6 @@ func TestUpdateFieldSet(t *testing.T) {
for name, tc := range map[string]struct {
id string
update bson.D
opts *options.UpdateOptions
expected bson.D
err *mongo.WriteError
stat *mongo.UpdateResult
Expand All @@ -62,19 +59,6 @@ func TestUpdateFieldSet(t *testing.T) {
UpsertedCount: 0,
},
},
"NonExistentUpsert": {
id: "non-existent",
update: bson.D{{"$set", bson.D{{"v", int32(42)}}}},
opts: &options.UpdateOptions{Upsert: pointer.ToBool(true)},
expected: bson.D{{"_id", "non-existent"}, {"v", int32(42)}},

stat: &mongo.UpdateResult{
MatchedCount: 0,
ModifiedCount: 0,
UpsertedCount: 1,
UpsertedID: "non-existent",
},
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
Expand Down