@@ -137,14 +137,6 @@ func newCollection(collection *mongo.Collection, brk breaker.Breaker) Collection
137137 }
138138}
139139
140- func newTestCollection (collection monCollection , brk breaker.Breaker ) * decoratedCollection {
141- return & decoratedCollection {
142- Collection : collection ,
143- name : "test" ,
144- brk : brk ,
145- }
146- }
147-
148140func (c * decoratedCollection ) Aggregate (ctx context.Context , pipeline any ,
149141 opts ... options.Lister [options.AggregateOptions ]) (cur * mongo.Cursor , err error ) {
150142 ctx , span := startSpan (ctx , aggregate )
@@ -185,6 +177,10 @@ func (c *decoratedCollection) BulkWrite(ctx context.Context, models []mongo.Writ
185177 return
186178}
187179
180+ func (c * decoratedCollection ) Clone (opts ... options.Lister [options.CollectionOptions ]) * mongo.Collection {
181+ return c .Collection .Clone (opts ... )
182+ }
183+
188184func (c * decoratedCollection ) CountDocuments (ctx context.Context , filter any ,
189185 opts ... options.Lister [options.CountOptions ]) (count int64 , err error ) {
190186 ctx , span := startSpan (ctx , countDocuments )
@@ -205,6 +201,10 @@ func (c *decoratedCollection) CountDocuments(ctx context.Context, filter any,
205201 return
206202}
207203
204+ func (c * decoratedCollection ) Database () * mongo.Database {
205+ return c .Collection .Database ()
206+ }
207+
208208func (c * decoratedCollection ) DeleteMany (ctx context.Context , filter any ,
209209 opts ... options.Lister [options.DeleteManyOptions ]) (res * mongo.DeleteResult , err error ) {
210210 ctx , span := startSpan (ctx , deleteMany )
@@ -266,6 +266,10 @@ func (c *decoratedCollection) Distinct(ctx context.Context, fieldName string, fi
266266 return
267267}
268268
269+ func (c * decoratedCollection ) Drop (ctx context.Context , opts ... options.Lister [options.DropCollectionOptions ]) error {
270+ return c .Collection .Drop (ctx , opts ... )
271+ }
272+
269273func (c * decoratedCollection ) EstimatedDocumentCount (ctx context.Context ,
270274 opts ... options.Lister [options.EstimatedDocumentCountOptions ]) (val int64 , err error ) {
271275 ctx , span := startSpan (ctx , estimatedDocumentCount )
@@ -391,6 +395,10 @@ func (c *decoratedCollection) FindOneAndUpdate(ctx context.Context, filter, upda
391395 return
392396}
393397
398+ func (c * decoratedCollection ) Indexes () mongo.IndexView {
399+ return c .Collection .Indexes ()
400+ }
401+
394402func (c * decoratedCollection ) InsertMany (ctx context.Context , documents []any ,
395403 opts ... options.Lister [options.InsertManyOptions ]) (res * mongo.InsertManyResult , err error ) {
396404 ctx , span := startSpan (ctx , insertMany )
@@ -511,22 +519,6 @@ func (c *decoratedCollection) UpdateOne(ctx context.Context, filter, update any,
511519 return
512520}
513521
514- func (c * decoratedCollection ) Clone (opts ... options.Lister [options.CollectionOptions ]) * mongo.Collection {
515- return c .Collection .Clone (opts ... )
516- }
517-
518- func (c * decoratedCollection ) Database () * mongo.Database {
519- return c .Collection .Database ()
520- }
521-
522- func (c * decoratedCollection ) Drop (ctx context.Context , opts ... options.Lister [options.DropCollectionOptions ]) error {
523- return c .Collection .Drop (ctx , opts ... )
524- }
525-
526- func (c * decoratedCollection ) Indexes () mongo.IndexView {
527- return c .Collection .Indexes ()
528- }
529-
530522func (c * decoratedCollection ) Watch (ctx context.Context , pipeline any , opts ... options.Lister [options.ChangeStreamOptions ]) (
531523 * mongo.ChangeStream , error ) {
532524 return c .Collection .Watch (ctx , pipeline , opts ... )
@@ -578,72 +570,70 @@ func isDupKeyError(err error) bool {
578570 return e .HasErrorCode (duplicateKeyCode )
579571}
580572
581- type (
582- // monCollection defines a MongoDB collection, used for unit test
583- monCollection interface {
584- // Aggregate executes an aggregation pipeline.
585- Aggregate (ctx context.Context , pipeline any , opts ... options.Lister [options.AggregateOptions ]) (
586- * mongo.Cursor , error )
587- // BulkWrite performs a bulk write operation.
588- BulkWrite (ctx context.Context , models []mongo.WriteModel , opts ... options.Lister [options.BulkWriteOptions ]) (
589- * mongo.BulkWriteResult , error )
590- // Clone creates a copy of this collection with the same settings.
591- Clone (opts ... options.Lister [options.CollectionOptions ]) * mongo.Collection
592- // CountDocuments returns the number of documents in the collection that match the filter.
593- CountDocuments (ctx context.Context , filter any , opts ... options.Lister [options.CountOptions ]) (int64 , error )
594- // Database returns the database that this collection is a part of.
595- Database () * mongo.Database
596- // DeleteMany deletes documents from the collection that match the filter.
597- DeleteMany (ctx context.Context , filter any , opts ... options.Lister [options.DeleteManyOptions ]) (
598- * mongo.DeleteResult , error )
599- // DeleteOne deletes at most one document from the collection that matches the filter.
600- DeleteOne (ctx context.Context , filter any , opts ... options.Lister [options.DeleteOneOptions ]) (
601- * mongo.DeleteResult , error )
602- // Distinct returns a list of distinct values for the given key across the collection.
603- Distinct (ctx context.Context , fieldName string , filter any ,
604- opts ... options.Lister [options.DistinctOptions ]) * mongo.DistinctResult
605- // Drop drops this collection from database.
606- Drop (ctx context.Context , opts ... options.Lister [options.DropCollectionOptions ]) error
607- // EstimatedDocumentCount returns an estimate of the count of documents in a collection
608- // using collection metadata.
609- EstimatedDocumentCount (ctx context.Context , opts ... options.Lister [options.EstimatedDocumentCountOptions ]) (int64 , error )
610- // Find finds the documents matching the provided filter.
611- Find (ctx context.Context , filter any , opts ... options.Lister [options.FindOptions ]) (* mongo.Cursor , error )
612- // FindOne returns up to one document that matches the provided filter.
613- FindOne (ctx context.Context , filter any , opts ... options.Lister [options.FindOneOptions ]) * mongo.SingleResult
614- // FindOneAndDelete returns at most one document that matches the filter. If the filter
615- // matches multiple documents, only the first document is deleted.
616- FindOneAndDelete (ctx context.Context , filter any , opts ... options.Lister [options.FindOneAndDeleteOptions ]) * mongo.SingleResult
617- // FindOneAndReplace returns at most one document that matches the filter. If the filter
618- // matches multiple documents, FindOneAndReplace returns the first document in the
619- // collection that matches the filter.
620- FindOneAndReplace (ctx context.Context , filter , replacement any ,
621- opts ... options.Lister [options.FindOneAndReplaceOptions ]) * mongo.SingleResult
622- // FindOneAndUpdate returns at most one document that matches the filter. If the filter
623- // matches multiple documents, FindOneAndUpdate returns the first document in the
624- // collection that matches the filter.
625- FindOneAndUpdate (ctx context.Context , filter , update any ,
626- opts ... options.Lister [options.FindOneAndUpdateOptions ]) * mongo.SingleResult
627- // Indexes returns the index view for this collection.
628- Indexes () mongo.IndexView
629- // InsertMany inserts the provided documents.
630- InsertMany (ctx context.Context , documents interface {}, opts ... options.Lister [options.InsertManyOptions ]) (* mongo.InsertManyResult , error )
631- // InsertOne inserts the provided document.
632- InsertOne (ctx context.Context , document any , opts ... options.Lister [options.InsertOneOptions ]) (* mongo.InsertOneResult , error )
633- // ReplaceOne replaces at most one document that matches the filter.
634- ReplaceOne (ctx context.Context , filter , replacement any ,
635- opts ... options.Lister [options.ReplaceOptions ]) (* mongo.UpdateResult , error )
636- // UpdateByID updates a single document matching the provided filter.
637- UpdateByID (ctx context.Context , id , update any ,
638- opts ... options.Lister [options.UpdateOneOptions ]) (* mongo.UpdateResult , error )
639- // UpdateMany updates the provided documents.
640- UpdateMany (ctx context.Context , filter , update any ,
641- opts ... options.Lister [options.UpdateManyOptions ]) (* mongo.UpdateResult , error )
642- // UpdateOne updates a single document matching the provided filter.
643- UpdateOne (ctx context.Context , filter , update any ,
644- opts ... options.Lister [options.UpdateOneOptions ]) (* mongo.UpdateResult , error )
645- // Watch returns a change stream cursor used to receive notifications of changes to the collection.
646- Watch (ctx context.Context , pipeline any , opts ... options.Lister [options.ChangeStreamOptions ]) (
647- * mongo.ChangeStream , error )
648- }
649- )
573+ // monCollection defines a MongoDB collection, used for unit test
574+ type monCollection interface {
575+ // Aggregate executes an aggregation pipeline.
576+ Aggregate (ctx context.Context , pipeline any , opts ... options.Lister [options.AggregateOptions ]) (
577+ * mongo.Cursor , error )
578+ // BulkWrite performs a bulk write operation.
579+ BulkWrite (ctx context.Context , models []mongo.WriteModel , opts ... options.Lister [options.BulkWriteOptions ]) (
580+ * mongo.BulkWriteResult , error )
581+ // Clone creates a copy of this collection with the same settings.
582+ Clone (opts ... options.Lister [options.CollectionOptions ]) * mongo.Collection
583+ // CountDocuments returns the number of documents in the collection that match the filter.
584+ CountDocuments (ctx context.Context , filter any , opts ... options.Lister [options.CountOptions ]) (int64 , error )
585+ // Database returns the database that this collection is a part of.
586+ Database () * mongo.Database
587+ // DeleteMany deletes documents from the collection that match the filter.
588+ DeleteMany (ctx context.Context , filter any , opts ... options.Lister [options.DeleteManyOptions ]) (
589+ * mongo.DeleteResult , error )
590+ // DeleteOne deletes at most one document from the collection that matches the filter.
591+ DeleteOne (ctx context.Context , filter any , opts ... options.Lister [options.DeleteOneOptions ]) (
592+ * mongo.DeleteResult , error )
593+ // Distinct returns a list of distinct values for the given key across the collection.
594+ Distinct (ctx context.Context , fieldName string , filter any ,
595+ opts ... options.Lister [options.DistinctOptions ]) * mongo.DistinctResult
596+ // Drop drops this collection from database.
597+ Drop (ctx context.Context , opts ... options.Lister [options.DropCollectionOptions ]) error
598+ // EstimatedDocumentCount returns an estimate of the count of documents in a collection
599+ // using collection metadata.
600+ EstimatedDocumentCount (ctx context.Context , opts ... options.Lister [options.EstimatedDocumentCountOptions ]) (int64 , error )
601+ // Find finds the documents matching the provided filter.
602+ Find (ctx context.Context , filter any , opts ... options.Lister [options.FindOptions ]) (* mongo.Cursor , error )
603+ // FindOne returns up to one document that matches the provided filter.
604+ FindOne (ctx context.Context , filter any , opts ... options.Lister [options.FindOneOptions ]) * mongo.SingleResult
605+ // FindOneAndDelete returns at most one document that matches the filter. If the filter
606+ // matches multiple documents, only the first document is deleted.
607+ FindOneAndDelete (ctx context.Context , filter any , opts ... options.Lister [options.FindOneAndDeleteOptions ]) * mongo.SingleResult
608+ // FindOneAndReplace returns at most one document that matches the filter. If the filter
609+ // matches multiple documents, FindOneAndReplace returns the first document in the
610+ // collection that matches the filter.
611+ FindOneAndReplace (ctx context.Context , filter , replacement any ,
612+ opts ... options.Lister [options.FindOneAndReplaceOptions ]) * mongo.SingleResult
613+ // FindOneAndUpdate returns at most one document that matches the filter. If the filter
614+ // matches multiple documents, FindOneAndUpdate returns the first document in the
615+ // collection that matches the filter.
616+ FindOneAndUpdate (ctx context.Context , filter , update any ,
617+ opts ... options.Lister [options.FindOneAndUpdateOptions ]) * mongo.SingleResult
618+ // Indexes returns the index view for this collection.
619+ Indexes () mongo.IndexView
620+ // InsertMany inserts the provided documents.
621+ InsertMany (ctx context.Context , documents interface {}, opts ... options.Lister [options.InsertManyOptions ]) (* mongo.InsertManyResult , error )
622+ // InsertOne inserts the provided document.
623+ InsertOne (ctx context.Context , document any , opts ... options.Lister [options.InsertOneOptions ]) (* mongo.InsertOneResult , error )
624+ // ReplaceOne replaces at most one document that matches the filter.
625+ ReplaceOne (ctx context.Context , filter , replacement any ,
626+ opts ... options.Lister [options.ReplaceOptions ]) (* mongo.UpdateResult , error )
627+ // UpdateByID updates a single document matching the provided filter.
628+ UpdateByID (ctx context.Context , id , update any ,
629+ opts ... options.Lister [options.UpdateOneOptions ]) (* mongo.UpdateResult , error )
630+ // UpdateMany updates the provided documents.
631+ UpdateMany (ctx context.Context , filter , update any ,
632+ opts ... options.Lister [options.UpdateManyOptions ]) (* mongo.UpdateResult , error )
633+ // UpdateOne updates a single document matching the provided filter.
634+ UpdateOne (ctx context.Context , filter , update any ,
635+ opts ... options.Lister [options.UpdateOneOptions ]) (* mongo.UpdateResult , error )
636+ // Watch returns a change stream cursor used to receive notifications of changes to the collection.
637+ Watch (ctx context.Context , pipeline any , opts ... options.Lister [options.ChangeStreamOptions ]) (
638+ * mongo.ChangeStream , error )
639+ }
0 commit comments