Skip to content

Commit

Permalink
Fix mock logger circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdeandrade committed Jul 26, 2017
1 parent 6e88f3f commit cfa07d2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions forward/request_sender_test.go
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/uber/ringpop-go/events"
"github.com/uber/ringpop-go/shared"
"github.com/uber/ringpop-go/test/mocks"
"github.com/uber/ringpop-go/test/mocks/logger"
"github.com/uber/tchannel-go"
)

Expand Down Expand Up @@ -76,8 +76,8 @@ func (s *requestSenderTestSuite) newDummies(mockSender *MockSender) *dummies {
}
}

func newDummyLogger() *mocks.Logger {
logger := &mocks.Logger{}
func newDummyLogger() *mocklogger.Logger {
logger := &mocklogger.Logger{}
logger.On("WithFields", mock.Anything).Return(logger)
logger.On("Warn", mock.Anything).Return(nil)
return logger
Expand Down
6 changes: 3 additions & 3 deletions logging/default_test.go
Expand Up @@ -25,16 +25,16 @@ import (

"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"github.com/uber/ringpop-go/test/mocks"
"github.com/uber/ringpop-go/test/mocks/logger"
)

type DefaultLoggingTestSuite struct {
suite.Suite
mockLogger *mocks.Logger
mockLogger *mocklogger.Logger
}

func (s *DefaultLoggingTestSuite) SetupTest() {
s.mockLogger = &mocks.Logger{}
s.mockLogger = &mocklogger.Logger{}
SetLogger(s.mockLogger)
// Set expected calls
s.mockLogger.On("Warn", mock.Anything)
Expand Down
8 changes: 4 additions & 4 deletions logging/facility_test.go
Expand Up @@ -27,17 +27,17 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"github.com/uber-common/bark"
"github.com/uber/ringpop-go/test/mocks"
"github.com/uber/ringpop-go/test/mocks/logger"
)

type LogFacilityTestSuite struct {
suite.Suite
mockLogger *mocks.Logger
mockLogger *mocklogger.Logger
facility *Facility
}

func (s *LogFacilityTestSuite) SetupTest() {
s.mockLogger = &mocks.Logger{}
s.mockLogger = &mocklogger.Logger{}
s.facility = NewFacility(s.mockLogger)
// Set expected calls
for _, meth := range []string{"Debug", "Info", "Warn", "Error", "Fatal", "Panic"} {
Expand Down Expand Up @@ -67,7 +67,7 @@ func (s *LogFacilityTestSuite) TestForwarding() {
}

func (s *LogFacilityTestSuite) TestSetLogger() {
newLogger := &mocks.Logger{}
newLogger := &mocklogger.Logger{}
s.facility.SetLogger(newLogger)
newLogger.On("Debug", mock.Anything)
msg := []interface{}{"msg"}
Expand Down
3 changes: 2 additions & 1 deletion options_test.go
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/uber/ringpop-go/membership"
"github.com/uber/ringpop-go/swim"
"github.com/uber/ringpop-go/test/mocks"
"github.com/uber/ringpop-go/test/mocks/logger"
"github.com/uber/tchannel-go"
)

Expand Down Expand Up @@ -104,7 +105,7 @@ func (s *RingpopOptionsTestSuite) TestChannelRequired() {
// TestLogger tests that the logger that's passed in gets applied correctly to
// the Ringpop instance.
func (s *RingpopOptionsTestSuite) TestLogger() {
mockLogger := &mocks.Logger{}
mockLogger := &mocklogger.Logger{}
// Ignore random ringpop messages
for _, meth := range []string{"Debug", "Info", "Warn", "Error"} {
mockLogger.On(meth, mock.Anything)
Expand Down
4 changes: 2 additions & 2 deletions swim/handlers_test.go
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/uber/ringpop-go/discovery/statichosts"
"github.com/uber/ringpop-go/logging"
"github.com/uber/ringpop-go/shared"
"github.com/uber/ringpop-go/test/mocks"
"github.com/uber/ringpop-go/test/mocks/logger"
"github.com/uber/tchannel-go"
)

Expand Down Expand Up @@ -161,7 +161,7 @@ func (s *HandlerTestSuite) TestNotImplementedHandler() {

// TestErrorHandler tests that the errorHandler logs the correct error message.
func (s *HandlerTestSuite) TestErrorHandler() {
logger := &mocks.Logger{}
logger := &mocklogger.Logger{}

// Make sure random log messages can be sent to this logger while it
// replaces the existing one.
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/logger.go → test/mocks/logger/logger.go
@@ -1,4 +1,4 @@
package mocks
package mocklogger

import "github.com/uber-common/bark"
import "github.com/stretchr/testify/mock"
Expand Down

0 comments on commit cfa07d2

Please sign in to comment.