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/mtest
for mgm as well, because it usesmongo-driver
library under the hood.For example, when you call the
FindByID
method on an mgm collection, it usesFindOne
method of the mongo-driver'sCollection
under the hood, so you can mockFinOne
and then test it.mgm's
Collection
embeds mongo-driver'sCollection
actually, 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
Collection
to mgm'sCollection
or it let us create the mgm Collection from mocked DB instance. If it needs, we have two solutions:Collection
constructor that gets the mock…