4 ms·
>if you want to use that package in combination with gomock, you're out of luck In general, libraries should offer structs, and you should declare your own int
by closeparen 6y ago
>if you want to use that package in combination with gomock, you're out of luck
In general, libraries should offer structs, and you should declare your own interfaces with the subset of methods that you require.
This is somewhat messy here because the timer channel is accessed by a field rather than a method, but you could write a struct that embeds time.Timer and adds C() as a method. Then both your wrapped time.Timer and your mock/fake could fulfill your interface.
- EdSchouten 6y agoThough that is true, remember that Go doesn’t support co/contravariance on interface types. Defining interfaces around existing types works, but quickly falls apart as soon as methods return concrete types. In those cases you need to write more complex wrappers, which is often not worth the hassle.