Skip to content

Commit

Permalink
upsert test docs and avoid dropping collection
Browse files Browse the repository at this point in the history
  • Loading branch information
yatesliang committed Sep 24, 2023
1 parent 412d804 commit 82b057f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/storage/mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mongo
import (
"bytes"
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"io"
Expand Down Expand Up @@ -121,10 +122,12 @@ func TestQueryKindUnexpectedErrorCases(t *testing.T) {
{"model1", "v1.1.1", 12345678, "error document with integer mod"},
{"model2", "v2.0.0", true, "error document with boolean mod"},
}
// clear collection before insert
coll.Drop(ctx)
// In case some docs were inserted into the collection before, using upsert instead.
for _, errDoc := range errDocs {
_, err = coll.InsertOne(ctx, errDoc, options.InsertOne().SetBypassDocumentValidation(true))
filter := bson.D{{"module", errDoc.Module}, {"version", errDoc.Version}}
update := bson.D{{"$set", bson.D{{"mod", errDoc.Mod}, {"info", errDoc.Info}}}}
opts := options.Update().SetUpsert(true).SetBypassDocumentValidation(true)
_, err = coll.UpdateOne(ctx, filter, update, opts)
if err != nil {
t.SkipNow()
}
Expand Down

0 comments on commit 82b057f

Please sign in to comment.