#Anyone got a good solution for mocking a module

3 messages · Page 1 of 1 (latest)

hearty jacinth
#

so I have some files ```go
// something.go
package something

import (
another/package/logger
...
)

func doesSomething() {
...
logger.log("This is a log")
}

// something_test.go
package something

func testDoesSomething(t *testing.t){
// I want to assert on a mocker logger package
}
, I know that I could monkey patch it so go
var myLogger = logger

serene sonnet
#

I think modern logging packages cache the logger in the context.Context that gets passed around. This would make it simple to replace the Logger with a test mock.

#

Usually when mocking you want to depend on a client-side interface.