From 154349329b5c020a8da02ee0d45f27e22d3ec243 Mon Sep 17 00:00:00 2001 From: Yates Date: Sat, 23 Sep 2023 23:51:57 -0700 Subject: [PATCH] upsert test docs and avoid dropping collection --- pkg/storage/mongo/mongo_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/storage/mongo/mongo_test.go b/pkg/storage/mongo/mongo_test.go index d87d7b6fa..81e32e0b6 100644 --- a/pkg/storage/mongo/mongo_test.go +++ b/pkg/storage/mongo/mongo_test.go @@ -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" @@ -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() }