You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Client and Subscription (and probably others I missed) being exposed from the centrifuge-go library as a struct makes it extremely difficult to mock them in unit tests. It would be nice if Client and Subscription were an interface instead of struct.
The text was updated successfully, but these errors were encountered:
shaunco
changed the title
Client type should be an interface to allow for mocking
Client and Subscription types should be an interface to allow for mocking
Sep 11, 2023
I see the point and agree that currently centrifuge-go is not simple to use in unit tests... At the same time Client and Subscription are not interfaces because we need a way to extend them with methods without worrying about breaking compatibility.
But mocking is harder - I do not have clear answer now, looks like the best you can do is use dependency injection techniques in your code where you are depending on centrifuge-go (I mean define interfaces in the place where you are using them). So you can granularly mock necessary parts.
Thanks @FZambia ! For now I built my own internal interface wrappers around Client and Subscription so that I can have one that just passes calls through to centrifuge-go and second generated by Mockery that can be used for unit testing.
As the centrifuge-go package stabilizes towards a v1, this would still be nice to have.
Client
andSubscription
(and probably others I missed) being exposed from the centrifuge-go library as astruct
makes it extremely difficult to mock them in unit tests. It would be nice ifClient
andSubscription
were aninterface
instead ofstruct
.The text was updated successfully, but these errors were encountered: