chore: inline log.Interface and handle empty and nil slices the same

This commit is contained in:
2022-06-17 09:53:03 +02:00
parent 18d12ed1b4
commit d5e322ca9e
2 changed files with 9 additions and 5 deletions
+7 -3
View File
@@ -31,7 +31,7 @@ import (
// Mock has a Logger for use in unit-testing
type Mock struct {
*sync.RWMutex
Logger log.Interface
log.Interface
Logged []string
}
@@ -48,8 +48,9 @@ var _ log.Handler = &Mock{}
// New instantiates a new Mock and sets the log.Handler to it
func New() *Mock {
mock := &Mock{
RWMutex: &sync.RWMutex{},
Logger: log.Log,
RWMutex: &sync.RWMutex{},
Interface: log.Log,
Logged: make([]string, 0),
}
log.SetHandler(mock)
return mock
@@ -60,5 +61,8 @@ func (m *Mock) Check(t testing.TB, wantLogged []string) {
t.Helper()
m.RLock()
defer m.RUnlock()
if wantLogged == nil {
wantLogged = []string{}
}
assert.Equal(t, wantLogged, m.Logged)
}