diff --git a/mocks.go b/mocks.go index 028e0d0..87cd060 100644 --- a/mocks.go +++ b/mocks.go @@ -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) } diff --git a/mocks_test.go b/mocks_test.go index 04d50e7..7ff42f6 100644 --- a/mocks_test.go +++ b/mocks_test.go @@ -50,7 +50,7 @@ func TestMock_Check(t *testing.T) { name: "different", fields: fields{Logged: []string{"same"}}, args: args{wantLogged: []string{"different"}}, - want: []string{"\n\tError Trace:\tmocks.go:63\n\t \t\t\t\tmocks_test.go:63\n\tError: \tNot equal: \n\t \texpected: []string{\"different\"}\n\t \tactual : []string{\"same\"}\n\t \t\n\t \tDiff:\n\t \t--- Expected\n\t \t+++ Actual\n\t \t@@ -1,3 +1,3 @@\n\t \t ([]string) (len=1) {\n\t \t- (string) (len=9) \"different\"\n\t \t+ (string) (len=4) \"same\"\n\t \t }\n\tTest: \t\n"}, + want: []string{"\n\tError Trace:\tmocks.go:67\n\t \t\t\t\tmocks_test.go:63\n\tError: \tNot equal: \n\t \texpected: []string{\"different\"}\n\t \tactual : []string{\"same\"}\n\t \t\n\t \tDiff:\n\t \t--- Expected\n\t \t+++ Actual\n\t \t@@ -1,3 +1,3 @@\n\t \t ([]string) (len=1) {\n\t \t- (string) (len=9) \"different\"\n\t \t+ (string) (len=4) \"same\"\n\t \t }\n\tTest: \t\n"}, }, } for _, tt := range tests { @@ -68,7 +68,7 @@ func TestMock_Check(t *testing.T) { func TestNew(t *testing.T) { logger := New() - logger.Logger.Info("logging") + logger.Info("logging") logger.Check(t, []string{"info: logging"}) }