[go-nuts] Re: Chasing high coverage with os level packages

2018-05-22 Thread ekocjan
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,

[go-nuts] Chasing high coverage with os level packages

2018-05-22 Thread ekocjan
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 }

Re: [go-nuts] Re: error handling needs syntactical sugar

2017-09-08 Thread ekocjan
> > P.S. someone else proposed wrapper with error handling in defer. > IMO it is as bad as watch - spooky, at distance, clunky. > That was me. My background is many years of C++ and it feels natural to me (RAII). I follow the pattern: there must be defer Close immediately after acquire

[go-nuts] Re: error handling needs syntactical sugar

2017-09-05 Thread ekocjan
I've been doing something like this for long chains where "handle error" is the same: func something() (x int, err error) { defer func() { if err != nil { // handle error } }() res, err = acquireResource() if err == nil { defer func() {