Skip to content

Unit Test #71

Answered by mehran-prs
tiagosouza488 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, I think you can use go.mongodb.org/mongo-driver/mongo/integration/mtest for mgm as well, because it uses mongo-driver library under the hood.
For example, when you call the FindByID method on an mgm collection, it uses FindOne method of the mongo-driver's Collection under the hood, so you can mock FinOne and then test it.
mgm's Collection embeds mongo-driver's Collection 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's Collection or it let us create the mgm Collection from mocked DB instance. If it needs, we have two solutions:

  • Add mgm Collection constructor that gets the mock…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mehran-prs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants