Inject Mock Instead of Actual Implementation in Tests, Using "wire"

893 views
Skip to first unread message

Kaveh Shahbazian

unread,
Apr 13, 2019, 9:19:58 AM4/13/19
to golang-nuts
Assume wire is going to be used for dependency injection here. And we have a provider function called NewService that returns an interface. 

There is the actual implementation for that interface that - for example - connects to PostgreSQL.

And we have also the mock for that interface.

Now we need to inject the mock for unit tests and the actual implementation if we are not testing.

How that can be done?

Kaveh Shahbazian

unread,
Apr 13, 2019, 12:25:12 PM4/13/19
to golang-nuts
BTW I am aware that some build tag tricks can be used to achieve this. I was wondering it there is an idiomatic way or any best practices for using wire.

Kaveh Shahbazian

unread,
Apr 15, 2019, 12:10:06 PM4/15/19
to golang-nuts
It is inside the documentation of wire - I should read it more carefully: here.
Reply all
Reply to author
Forward
0 new messages