Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
zaporter committed Feb 11, 2024
1 parent a20b4fe commit 4a9904a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ issues:
- exhaustive
- goconst
- gosec
- lll # line length is fine
- path: /doc.go$
linters:
- lll
Expand Down
15 changes: 12 additions & 3 deletions update/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,24 @@ import (
"go.mongodb.org/mongo-driver/bson"
)

func UpdateDocument(document, updates bson.D) (bson.D, error) {
if len(updates) == 0 {
// UpdateDocument updates the provided bson.D document using the passed updateDoc.
// it returns that new document.
//
// The passed updateDoc must conform to the mongodb Update Operator spec
// https://www.mongodb.com/docs/manual/reference/operator/update/
//
// Under the hood, this uses FerretDB to update the document.
//
//nolint:revive
func UpdateDocument(document, updateDoc bson.D) (bson.D, error) {
if len(updateDoc) == 0 {
return nil, errors.New("update document must have at least one element")
}
doc, err := convertDToDocument(document)
if err != nil {
return nil, err
}
convertedUpdates, err := convertUpdateParams(updates)
convertedUpdates, err := convertUpdateParams(updateDoc)
if err != nil {
return nil, errors.Wrap(err, "convert update operations to update params")
}
Expand Down
16 changes: 7 additions & 9 deletions update/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,39 +158,39 @@ func TestBehaviorParity(t *testing.T) {
// "$currentDate": mapT{"field": true},
// },
// skip: true,
//},
// },
//{
// name: "currentDate true",
// object: bson.D{{"field", 1}},
// update: mapT{
// "$currentDate": mapT{"field": true},
// },
// skip: true,
//},
// },
//{
// name: "currentDate nested set",
// object: bson.D{{"field", 1}},
// update: mapT{
// "$currentDate": mapT{"unknown.bar": true},
// },
// skip: true,
//},
// },
//{
// name: "currentDate document timestamp",
// object: bson.D{{"field", 1}},
// update: mapT{
// "$currentDate": mapT{"field": mapT{"$type": "timestamp"}},
// },
// skip: true,
//},
// },
//{
// name: "currentDate document date",
// object: bson.D{{"field", 1}},
// update: mapT{
// "$currentDate": mapT{"field": mapT{"$type": "date"}},
// },
// skip: true,
//},
// },
//{
// name: "currentDate document anything else",
// object: bson.D{{"field", 1}},
Expand Down Expand Up @@ -324,7 +324,6 @@ func TestBehaviorParity(t *testing.T) {
name: "max on array field",
object: objT{{"values", primitive.A{10, 20, 30}}},
update: upT{{"$max", mapT{"values": 40}}},

},
{
name: "max on empty document",
Expand Down Expand Up @@ -1501,7 +1500,7 @@ func TestBehaviorParity(t *testing.T) {
tcObjectWithID := bson.D{{Key: "_id", Value: uuid.New().String()}}
tcObjectWithID = append(tcObjectWithID, tc.object...)
// perform operation in mongo
mongoResult, mongoErr := performMongoUpdate(t, ctx, col, tcObjectWithID, tc.update)
mongoResult, mongoErr := performMongoUpdate(ctx, t, col, tcObjectWithID, tc.update)
// perform my in-memory operation
myResult, myError := self.UpdateDocument(tcObjectWithID, tc.update)

Expand Down Expand Up @@ -1531,8 +1530,7 @@ func TestBehaviorParity(t *testing.T) {
}
}

func performMongoUpdate(t *testing.T,
ctx context.Context,
func performMongoUpdate(ctx context.Context, t *testing.T,
col *mongo.Collection,
object bson.D,
update bson.D,
Expand Down

0 comments on commit 4a9904a

Please sign in to comment.