diff --git a/go.mod b/go.mod index 41db88b5..ef0b2057 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/testcontainers/testcontainers-go/modules/nats v0.44.0 github.com/testcontainers/testcontainers-go/modules/postgres v0.44.0 github.com/testcontainers/testcontainers-go/modules/redpanda v0.44.0 - go.mongodb.org/mongo-driver v1.17.10 + go.mongodb.org/mongo-driver/v2 v2.9.3 go.uber.org/zap v1.28.0 golang.org/x/crypto v0.58.0 golang.org/x/oauth2 v0.37.0 @@ -117,7 +117,6 @@ require ( github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect - github.com/golang/snappy v0.0.4 // indirect github.com/google/flatbuffers v23.5.26+incompatible // indirect github.com/google/gnostic-models v0.7.0 // indirect github.com/google/go-cmp v0.7.0 // indirect @@ -153,7 +152,6 @@ require ( github.com/moby/term v0.5.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nkeys v0.4.16 // indirect github.com/nats-io/nuid v1.0.1 // indirect @@ -179,7 +177,7 @@ require ( github.com/x448/float16 v0.8.4 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect - github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/scram v1.2.0 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect diff --git a/go.sum b/go.sum index 8b2ee0c1..e33b5d7b 100644 --- a/go.sum +++ b/go.sum @@ -236,8 +236,6 @@ github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8J github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= -github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/cel-go v0.31.0 h1:H0bhpFTqOvmHrBGrWKp7ZlhBm5Hh8PYUEXnwxT1LL7A= github.com/google/cel-go v0.31.0/go.mod h1:X0bD6iVNR8pkROSOoHVdgTkzmRcosof7WQqCD6wcMc8= github.com/google/flatbuffers v23.5.26+incompatible h1:M9dgRyhJemaM4Sw8+66GHBu8ioaQmyPLg1b8VwK5WJg= @@ -355,8 +353,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFdJifH4BDsTlE89Zl93FEloxaWZfGcifgq8= github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= -github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/nats-io/nats.go v1.55.0 h1:Ng8QKHdvdHIWoaiq0+d/aH1BWkxvcJxWJ0Y/9BPKx3M= @@ -473,8 +469,8 @@ github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= -github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= -github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= +github.com/xdg-go/scram v1.2.0 h1:bYKF2AEwG5rqd1BumT4gAnvwU/M9nBp2pTSxeZw7Wvs= +github.com/xdg-go/scram v1.2.0/go.mod h1:3dlrS0iBaWKYVt2ZfA4cj48umJZ+cAEbR6/SjLA88I8= github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU= @@ -494,8 +490,8 @@ go.etcd.io/etcd/client/pkg/v3 v3.7.0 h1:sW9njJzS3vXKcAJjjLQ4nk+avNUJ12Bcijcx8ehU go.etcd.io/etcd/client/pkg/v3 v3.7.0/go.mod h1:cnzZGIUzSfjEwLC6UBVsSXlEK1eepS/JUD7wE6PLRT0= go.etcd.io/etcd/client/v3 v3.7.0 h1:5MHO37VbPB87VRPKUXEcicjeQWiTSjpPv3Ume8xPx20= go.etcd.io/etcd/client/v3 v3.7.0/go.mod h1:DJ382WuwjmbowjPDyaaQ0idWXy4dh91XRhe4FOrb9vM= -go.mongodb.org/mongo-driver v1.17.10 h1:kdAgQvu8TROXZpSkJQd5wzfaNCCrMbpZyKFtQ6qkPCE= -go.mongodb.org/mongo-driver v1.17.10/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.9.3 h1:wyiWaPGYaFqRmhjNOXwlK6Cu8Qf35zFH4euH2NBBj34= +go.mongodb.org/mongo-driver/v2 v2.9.3/go.mod h1:SHKN0IWkKmEVGHLjXnni6s4wPKX4v86FTgOeJJFuXcA= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/detectors/gcp v1.45.0 h1:9jR0ZPRok9ryaOQ2Wx8rg5F7Aon59mxrqbVI60/vlBk= diff --git a/internal/sink/mongodb/backend.go b/internal/sink/mongodb/backend.go index 8e682b42..d6e92259 100644 --- a/internal/sink/mongodb/backend.go +++ b/internal/sink/mongodb/backend.go @@ -9,9 +9,9 @@ import ( "fmt" "time" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" kollectdevv1alpha1 "github.com/platformrelay/kollect/api/v1alpha1" "github.com/platformrelay/kollect/internal/collect" @@ -67,12 +67,12 @@ func (a mongoCollectionAdmin) EnsureUniqueIndex(ctx context.Context, keys bson.D } type deleteManyCollection interface { - DeleteMany(context.Context, interface{}, ...*options.DeleteOptions) (*mongo.DeleteResult, error) + DeleteMany(context.Context, interface{}, ...options.Lister[options.DeleteManyOptions]) (*mongo.DeleteResult, error) } type exportCollection interface { - ReplaceOne(context.Context, interface{}, interface{}, ...*options.ReplaceOptions) (*mongo.UpdateResult, error) - DeleteMany(context.Context, interface{}, ...*options.DeleteOptions) (*mongo.DeleteResult, error) + ReplaceOne(context.Context, interface{}, interface{}, ...options.Lister[options.ReplaceOptions]) (*mongo.UpdateResult, error) + DeleteMany(context.Context, interface{}, ...options.Lister[options.DeleteManyOptions]) (*mongo.DeleteResult, error) } // NewBackend constructs a MongoDB sink backend. @@ -99,7 +99,7 @@ func NewBackend( return nil, err } - client, err := mongo.Connect(connectCtx, opts) + client, err := mongo.Connect(opts) if err != nil { return nil, fmt.Errorf("mongodb connect: %w", err) } diff --git a/internal/sink/mongodb/backend_collection_test.go b/internal/sink/mongodb/backend_collection_test.go index c3508888..1bd462b6 100644 --- a/internal/sink/mongodb/backend_collection_test.go +++ b/internal/sink/mongodb/backend_collection_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type fakeCollectionAdmin struct { diff --git a/internal/sink/mongodb/backend_mongo_admin_test.go b/internal/sink/mongodb/backend_mongo_admin_test.go index 700d9104..b9c08c59 100644 --- a/internal/sink/mongodb/backend_mongo_admin_test.go +++ b/internal/sink/mongodb/backend_mongo_admin_test.go @@ -7,41 +7,101 @@ import ( "context" "testing" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo/integration/mtest" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" + "go.mongodb.org/mongo-driver/v2/x/mongo/driver/drivertest" + "go.mongodb.org/mongo-driver/v2/x/mongo/driver/xoptions" ) +// mockAdmin returns a mongoCollectionAdmin over a client whose deployment answers +// each command with the next of responses (OP_MSG), so the real driver code path of +// the admin methods runs without a server. mongo-driver v2 moved mtest under +// internal/; drivertest.MockDeployment is the public equivalent of its mock client. +func mockAdmin(t *testing.T, responses ...bson.D) mongoCollectionAdmin { + t.Helper() + + opts := options.Client() + if err := xoptions.SetInternalClientOptions(opts, "deployment", drivertest.NewMockDeployment(responses...)); err != nil { + t.Fatalf("set mock deployment: %v", err) + } + + client, err := mongo.Connect(opts) + if err != nil { + t.Fatalf("mongo.Connect: %v", err) + } + t.Cleanup(func() { _ = client.Disconnect(context.Background()) }) + + db := client.Database("db") + + return mongoCollectionAdmin{db: db, coll: db.Collection("items")} +} + +func cursorResponse(ns string, batch ...bson.D) bson.D { + docs := make(bson.A, 0, len(batch)) + for _, doc := range batch { + docs = append(docs, doc) + } + + return bson.D{ + {Key: "ok", Value: 1}, + {Key: "cursor", Value: bson.D{ + {Key: "id", Value: int64(0)}, + {Key: "ns", Value: ns}, + {Key: "firstBatch", Value: docs}, + }}, + } +} + +func okResponse() bson.D { + return bson.D{{Key: "ok", Value: 1}} +} + func TestMongoCollectionAdmin_listCreateIndex(t *testing.T) { t.Parallel() - mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock)) - mt.Run("list names", func(mt *mtest.T) { - mt.AddMockResponses( - mtest.CreateCursorResponse(1, "db.$cmd.listCollections", mtest.FirstBatch, bson.D{{Key: "name", Value: "items"}}), - ) - admin := mongoCollectionAdmin{db: mt.Client.Database("db"), coll: mt.Client.Database("db").Collection("items")} + t.Run("list names", func(t *testing.T) { + t.Parallel() + + admin := mockAdmin(t, cursorResponse("db.$cmd.listCollections", bson.D{{Key: "name", Value: "items"}})) names, err := admin.ListCollectionNames(context.Background(), bson.M{"name": "items"}) if err != nil { - mt.Fatalf("ListCollectionNames: %v", err) + t.Fatalf("ListCollectionNames: %v", err) } - if len(names) != 1 { - mt.Fatalf("names = %v", names) + if len(names) != 1 || names[0] != "items" { + t.Fatalf("names = %v, want [items]", names) } }) - mt.Run("create collection", func(mt *mtest.T) { - mt.AddMockResponses(mtest.CreateSuccessResponse()) - admin := mongoCollectionAdmin{db: mt.Client.Database("db"), coll: mt.Client.Database("db").Collection("items")} + t.Run("create collection", func(t *testing.T) { + t.Parallel() + + admin := mockAdmin(t, okResponse()) if err := admin.CreateCollection(context.Background(), "items"); err != nil { - mt.Fatalf("CreateCollection: %v", err) + t.Fatalf("CreateCollection: %v", err) } }) - mt.Run("ensure index", func(mt *mtest.T) { - mt.AddMockResponses(mtest.CreateSuccessResponse()) - admin := mongoCollectionAdmin{db: mt.Client.Database("db"), coll: mt.Coll} + t.Run("ensure index", func(t *testing.T) { + t.Parallel() + + admin := mockAdmin(t, okResponse()) if err := admin.EnsureUniqueIndex(context.Background(), bson.D{{Key: "source_uid", Value: 1}}); err != nil { - mt.Fatalf("EnsureUniqueIndex: %v", err) + t.Fatalf("EnsureUniqueIndex: %v", err) + } + }) + + t.Run("server error surfaces", func(t *testing.T) { + t.Parallel() + + admin := mockAdmin(t, bson.D{ + {Key: "ok", Value: 0}, + {Key: "code", Value: 13}, + {Key: "errmsg", Value: "not authorized"}, + {Key: "codeName", Value: "Unauthorized"}, + }) + if err := admin.CreateCollection(context.Background(), "items"); err == nil { + t.Fatal("CreateCollection: want the server's error, got nil") } }) } diff --git a/internal/sink/mongodb/backend_test.go b/internal/sink/mongodb/backend_test.go index d395465c..da543f91 100644 --- a/internal/sink/mongodb/backend_test.go +++ b/internal/sink/mongodb/backend_test.go @@ -11,9 +11,9 @@ import ( "testing" "time" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" kollectdevv1alpha1 "github.com/platformrelay/kollect/api/v1alpha1" "github.com/platformrelay/kollect/internal/collect" @@ -100,7 +100,7 @@ type fakeDeleteManyCollection struct { func (f *fakeDeleteManyCollection) DeleteMany( _ context.Context, filter interface{}, - _ ...*options.DeleteOptions, + _ ...options.Lister[options.DeleteManyOptions], ) (*mongo.DeleteResult, error) { f.gotFilter = filter if f.err != nil { diff --git a/internal/sink/mongodb/ca_trust.go b/internal/sink/mongodb/ca_trust.go index 5c61c627..87a1247c 100644 --- a/internal/sink/mongodb/ca_trust.go +++ b/internal/sink/mongodb/ca_trust.go @@ -10,7 +10,7 @@ import ( "net/url" "strings" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/mongo/options" kollecterrors "github.com/platformrelay/kollect/internal/errors" "github.com/platformrelay/kollect/internal/sink/netguard" diff --git a/internal/sink/mongodb/ca_trust_integration_test.go b/internal/sink/mongodb/ca_trust_integration_test.go index c4ee3803..072ab044 100644 --- a/internal/sink/mongodb/ca_trust_integration_test.go +++ b/internal/sink/mongodb/ca_trust_integration_test.go @@ -13,7 +13,7 @@ import ( "testing" "time" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" "github.com/platformrelay/kollect/internal/collect" "github.com/platformrelay/kollect/internal/sink/sinktls/sinktlstest" diff --git a/internal/sink/mongodb/ca_trust_test.go b/internal/sink/mongodb/ca_trust_test.go index 37702d7a..d8d14b6b 100644 --- a/internal/sink/mongodb/ca_trust_test.go +++ b/internal/sink/mongodb/ca_trust_test.go @@ -15,9 +15,9 @@ import ( "testing" "time" - "go.mongodb.org/mongo-driver/mongo/options" - "go.mongodb.org/mongo-driver/x/mongo/driver/connstring" - "go.mongodb.org/mongo-driver/x/mongo/driver/dns" + "go.mongodb.org/mongo-driver/v2/mongo/options" + "go.mongodb.org/mongo-driver/v2/x/mongo/driver/connstring" + "go.mongodb.org/mongo-driver/v2/x/mongo/driver/dns" kollectdevv1alpha1 "github.com/platformrelay/kollect/api/v1alpha1" kollecterrors "github.com/platformrelay/kollect/internal/errors" diff --git a/internal/sink/mongodb/connection.go b/internal/sink/mongodb/connection.go index e308bee9..a46805fc 100644 --- a/internal/sink/mongodb/connection.go +++ b/internal/sink/mongodb/connection.go @@ -8,7 +8,7 @@ import ( "fmt" "time" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" kollectdevv1alpha1 "github.com/platformrelay/kollect/api/v1alpha1" ) @@ -35,7 +35,7 @@ func TestConnection( return err } - client, err := mongo.Connect(probeCtx, opts) + client, err := mongo.Connect(opts) if err != nil { return fmt.Errorf("mongodb connect: %w", err) } diff --git a/internal/sink/mongodb/errors.go b/internal/sink/mongodb/errors.go index 236340a6..3d4ac12f 100644 --- a/internal/sink/mongodb/errors.go +++ b/internal/sink/mongodb/errors.go @@ -6,7 +6,7 @@ package mongodb import ( "errors" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" kollecterrors "github.com/platformrelay/kollect/internal/errors" ) diff --git a/internal/sink/mongodb/errors_test.go b/internal/sink/mongodb/errors_test.go index 4cb2a5b8..6ddd8e26 100644 --- a/internal/sink/mongodb/errors_test.go +++ b/internal/sink/mongodb/errors_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" kollecterrors "github.com/platformrelay/kollect/internal/errors" ) diff --git a/internal/sink/mongodb/export_integration_test.go b/internal/sink/mongodb/export_integration_test.go index aa52bf24..b5efed87 100644 --- a/internal/sink/mongodb/export_integration_test.go +++ b/internal/sink/mongodb/export_integration_test.go @@ -15,9 +15,9 @@ import ( "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" kollectdevv1alpha1 "github.com/platformrelay/kollect/api/v1alpha1" "github.com/platformrelay/kollect/internal/collect" @@ -335,7 +335,7 @@ func TestExportMongoDB_existingProvisioningModeSuccess(t *testing.T) { collection = "preexisting" ) - client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri)) + client, err := mongo.Connect(options.Client().ApplyURI(uri)) if err != nil { t.Fatalf("connect: %v", err) } @@ -764,21 +764,21 @@ func documentAttribute( } filter["source_uid"] = sourceUID - var doc struct { - Payload map[string]any `bson:"payload"` - } - if err := coll.FindOne(ctx, filter).Decode(&doc); err != nil { + // Read the stored BSON directly: driver v2 decodes nested documents in an + // `any` to bson.D, so a map[string]any assertion would depend on the decoder. + raw, err := coll.FindOne(ctx, filter).Raw() + if err != nil { return 0, err } - attrs, ok := doc.Payload["attributes"].(map[string]any) - if !ok { - return 0, fmt.Errorf("payload attributes missing for uid %s", sourceUID) + if _, err := raw.LookupErr("payload", "attributes"); err != nil { + return 0, fmt.Errorf("payload attributes missing for uid %s: %w", sourceUID, err) } - value, ok := attrs[attr].(float64) + field := raw.Lookup("payload", "attributes", attr) + value, ok := field.DoubleOK() if !ok { - return 0, fmt.Errorf("attribute %q type = %T, want float64", attr, attrs[attr]) + return 0, fmt.Errorf("attribute %q BSON type = %s, want double", attr, field.Type) } return value, nil diff --git a/internal/sink/mongodb/export_plan.go b/internal/sink/mongodb/export_plan.go index 21e9c0a2..66662e95 100644 --- a/internal/sink/mongodb/export_plan.go +++ b/internal/sink/mongodb/export_plan.go @@ -4,7 +4,7 @@ package mongodb import ( - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" "github.com/platformrelay/kollect/internal/collect" "github.com/platformrelay/kollect/internal/pathvalidate" diff --git a/internal/sink/mongodb/export_surface_test.go b/internal/sink/mongodb/export_surface_test.go index ccd10a83..115a2eb4 100644 --- a/internal/sink/mongodb/export_surface_test.go +++ b/internal/sink/mongodb/export_surface_test.go @@ -9,9 +9,9 @@ import ( "strings" "testing" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" "github.com/platformrelay/kollect/internal/collect" ) @@ -29,7 +29,7 @@ func (f *fakeExportCollection) ReplaceOne( _ context.Context, filter interface{}, _ interface{}, - _ ...*options.ReplaceOptions, + _ ...options.Lister[options.ReplaceOptions], ) (*mongo.UpdateResult, error) { f.replaceCalls++ if m, ok := filter.(bson.M); ok { @@ -44,7 +44,7 @@ func (f *fakeExportCollection) ReplaceOne( func (f *fakeExportCollection) DeleteMany( _ context.Context, filter interface{}, - _ ...*options.DeleteOptions, + _ ...options.Lister[options.DeleteManyOptions], ) (*mongo.DeleteResult, error) { f.deleteCalls++ if m, ok := filter.(bson.M); ok { @@ -106,10 +106,7 @@ func TestBackend_Export_classifiesReplaceError(t *testing.T) { func TestBackend_Close_disconnectsClient(t *testing.T) { t.Parallel() - ctx, cancel := context.WithTimeout(context.Background(), connectTimeout) - defer cancel() - - client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://127.0.0.1:1")) + client, err := mongo.Connect(options.Client().ApplyURI("mongodb://127.0.0.1:1")) if err != nil { t.Fatalf("mongo.Connect: %v", err) }