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?