Unit Test #71
-
|
I looked through all the examples in the repository but I didn't find a way to use mocks. Is something like go.mongodb.org/mongo-driver/mongo/integration/mtest possible? ` } |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Yes, I think you can use I'm just unsure whether we need to provided the mocked mongo-driver's
c:=mgm.CollectionByName("test")
c.Collection=mt.Coll // assign mocked collection as a mongo-driver collection to mgm Collection |
Beta Was this translation helpful? Give feedback.
Yes, I think you can use
go.mongodb.org/mongo-driver/mongo/integration/mtestfor mgm as well, because it usesmongo-driverlibrary under the hood.For example, when you call the
FindByIDmethod on an mgm collection, it usesFindOnemethod of the mongo-driver'sCollectionunder the hood, so you can mockFinOneand then test it.mgm's
Collectionembeds mongo-driver'sCollectionactually, so you can mock all of the mongo-driver methods as well.I'm just unsure whether we need to provided the mocked mongo-driver's
Collectionto mgm'sCollectionor it let us create the mgm Collection from mocked DB instance. If it needs, we have two solutions:Collectionconstructor that gets the mock…