News for hackers. Stuff that matters.
Re:Mocking time and testing event loops in Go by closeparen on Monday May 25, 2020 @02:11PM (#23303307)
>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.

Re:Mocking time and testing event loops in Go by EdSchouten on Tuesday May 26, 2020 @12:11AM (#23307338)
Though 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.