On Thu, Dec 27, 2012 at 9:41 PM, Holger Rapp <
sir...@gmx.de> wrote:
> So here is my problem: I can provide an interface to my own code that I can
> mock out and that handles time stuff, but how can I mock out e.g. time.After
> or time.Now, so that the timeout code in net.Conn also works with my
> synthetic time?
You can't mock out time.Now and friends; they are functions. You can,
however, define your own interface, like
type Clock interface {
Now() time.Time
After(d time.Duration) <-chan time.Time
}
and provide a concrete implementation
type realClock struct{}
func (realClock) Now() time.Time { return time.Now() }
func (realClock) After(d time.Duration) <-chan time.Time { return
time.After(d) }
and a testing implementation.