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 1543493
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 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 @@ -122,9 +123,11 @@ func TestQueryKindUnexpectedErrorCases(t *testing.T) {
{"model2", "v2.0.0", true, "error document with boolean mod"},
}
// clear collection before insert
coll.Drop(ctx)
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 1543493

Please sign in to comment.