I've found a solution, but it's not as nice as interfaces: Injectable function type: func(l *eventlog.Log, eid uint32, msg string) error
Struct methods convert directly to this type without wrappers: (* eventlog.Log).Info and (*eventlog.Log).Error On Tuesday, May 22, 2018 at 12:46:28 PM UTC+2, eko...@gmail.com wrote: > > Let's say I want to unit test code that is using eventlog.Open: > https://godoc.org/golang.org/x/sys/windows/svc/eventlog#Open > > First I define an interface that matches eventlog.Log: > type WindowsEventLogger interface { > Info(eid uint32, msg string) error > Error(eid uint32, msg string) error > } > > The problem is that eventlog.Open does not convert directly to: > func(source string) (WindowsEventLogger, error) > > I have to create a wrapper function that is replaced in the test with a > testing implementation of WindowsEventLogger: > func(source string) (WindowsEventLogger, error) { return > eventlog.Open(source) > } > > However this means there's an extra line of code that will not be called > from the test and makes the coverage artificially lower. Is there any way > to avoid the lower coverage score? > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.