lookout icon indicating copy to clipboard operation
lookout copied to clipboard

Can't mock logger anymore

Open smacker opened this issue 6 years ago • 5 comments

After https://github.com/src-d/lookout/pull/439 it's impossible to mock logger in tests anymore.

smacker avatar Jan 04 '19 12:01 smacker

Is there any more context? are tests failing? Any specific place where we need to mock a logger?

carlosms avatar Jan 04 '19 13:01 carlosms

screenshot 2019-01-04 at 14 37 08

Tests are failing obviously.

smacker avatar Jan 04 '19 13:01 smacker

As a solution, we can do in ctxlog/context.go:

var NewLogger = log.New

then we will be able to mock it in the tests. What do you think @carlosms ?

smacker avatar Jan 08 '19 11:01 smacker

It looks risk... but we can go that way to unblock the issue and maybe rethink later if we find a better solution.

Can't we change the go-log DefaultFactory instead? I think it should be picked by ctxlog.Get -> log.New

carlosms avatar Jan 11 '19 12:01 carlosms

Sadly we can not. LoggerFactory isn't an interface but a struct defined in go-log. And there is no way to replace logrus in New with something else.

I'll proceed with the solution from above to unblock related PR but keep this issue open because I don't like this solution too much.

smacker avatar Jan 11 '19 13:01 smacker