Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove MockLogger #2554

Merged
merged 4 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions api/admin/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,23 @@ import (
type loadVMsTest struct {
admin *Admin
ctrl *gomock.Controller
mockLog *logging.MockLogger
mockVMManager *vms.MockManager
mockVMRegistry *registry.MockVMRegistry
}

func initLoadVMsTest(t *testing.T) *loadVMsTest {
ctrl := gomock.NewController(t)

mockLog := logging.NewMockLogger(ctrl)
mockVMRegistry := registry.NewMockVMRegistry(ctrl)
mockVMManager := vms.NewMockManager(ctrl)

return &loadVMsTest{
admin: &Admin{Config: Config{
Log: mockLog,
Log: logging.NoLog{},
VMRegistry: mockVMRegistry,
VMManager: mockVMManager,
}},
ctrl: ctrl,
mockLog: mockLog,
mockVMManager: mockVMManager,
mockVMRegistry: mockVMRegistry,
}
Expand Down Expand Up @@ -67,7 +64,6 @@ func TestLoadVMsSuccess(t *testing.T) {
id2: alias2[1:],
}

resources.mockLog.EXPECT().Debug(gomock.Any(), gomock.Any()).Times(1)
resources.mockVMRegistry.EXPECT().ReloadWithReadLock(gomock.Any()).Times(1).Return(newVMs, failedVMs, nil)
resources.mockVMManager.EXPECT().Aliases(id1).Times(1).Return(alias1, nil)
resources.mockVMManager.EXPECT().Aliases(id2).Times(1).Return(alias2, nil)
Expand All @@ -84,7 +80,6 @@ func TestLoadVMsReloadFails(t *testing.T) {

resources := initLoadVMsTest(t)

resources.mockLog.EXPECT().Debug(gomock.Any(), gomock.Any()).Times(1)
// Reload fails
resources.mockVMRegistry.EXPECT().ReloadWithReadLock(gomock.Any()).Times(1).Return(nil, nil, errTest)

Expand All @@ -108,7 +103,6 @@ func TestLoadVMsGetAliasesFails(t *testing.T) {
// every vm is at least aliased to itself.
alias1 := []string{id1.String(), "vm1-alias-1", "vm1-alias-2"}

resources.mockLog.EXPECT().Debug(gomock.Any(), gomock.Any()).Times(1)
resources.mockVMRegistry.EXPECT().ReloadWithReadLock(gomock.Any()).Times(1).Return(newVMs, failedVMs, nil)
resources.mockVMManager.EXPECT().Aliases(id1).Times(1).Return(alias1, nil)
resources.mockVMManager.EXPECT().Aliases(id2).Times(1).Return(nil, errTest)
Expand Down
19 changes: 6 additions & 13 deletions api/info/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ var errTest = errors.New("non-nil error")
type getVMsTest struct {
info *Info
ctrl *gomock.Controller
mockLog *logging.MockLogger
mockVMManager *vms.MockManager
}

func initGetVMsTest(t *testing.T) *getVMsTest {
ctrl := gomock.NewController(t)

service := Info{}
mockLog := logging.NewMockLogger(ctrl)
mockVMManager := vms.NewMockManager(ctrl)

service.log = mockLog
service.VMManager = mockVMManager

return &getVMsTest{
info: &service,
info: &Info{
Parameters: Parameters{
VMManager: mockVMManager,
},
log: logging.NoLog{},
},
ctrl: ctrl,
mockLog: mockLog,
mockVMManager: mockVMManager,
}
}
Expand All @@ -62,7 +58,6 @@ func TestGetVMsSuccess(t *testing.T) {
id2: alias2[1:],
}

resources.mockLog.EXPECT().Debug(gomock.Any(), gomock.Any()).Times(1)
resources.mockVMManager.EXPECT().ListFactories().Times(1).Return(vmIDs, nil)
resources.mockVMManager.EXPECT().Aliases(id1).Times(1).Return(alias1, nil)
resources.mockVMManager.EXPECT().Aliases(id2).Times(1).Return(alias2, nil)
Expand All @@ -76,7 +71,6 @@ func TestGetVMsSuccess(t *testing.T) {
func TestGetVMsVMsListFactoriesFails(t *testing.T) {
resources := initGetVMsTest(t)

resources.mockLog.EXPECT().Debug(gomock.Any(), gomock.Any()).Times(1)
resources.mockVMManager.EXPECT().ListFactories().Times(1).Return(nil, errTest)

reply := GetVMsReply{}
Expand All @@ -93,7 +87,6 @@ func TestGetVMsGetAliasesFails(t *testing.T) {
vmIDs := []ids.ID{id1, id2}
alias1 := []string{id1.String(), "vm1-alias-1", "vm1-alias-2"}

resources.mockLog.EXPECT().Debug(gomock.Any(), gomock.Any()).Times(1)
resources.mockVMManager.EXPECT().ListFactories().Times(1).Return(vmIDs, nil)
resources.mockVMManager.EXPECT().Aliases(id1).Times(1).Return(alias1, nil)
resources.mockVMManager.EXPECT().Aliases(id2).Times(1).Return(nil, errTest)
Expand Down
1 change: 0 additions & 1 deletion scripts/mocks.mockgen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ github.com/ava-labs/avalanchego/snow/validators=SubnetConnector=snow/validators/
github.com/ava-labs/avalanchego/utils/crypto/keychain=Ledger=utils/crypto/keychain/mock_ledger.go
github.com/ava-labs/avalanchego/utils/filesystem=Reader=utils/filesystem/mock_io.go
github.com/ava-labs/avalanchego/utils/hashing=Hasher=utils/hashing/mock_hasher.go
github.com/ava-labs/avalanchego/utils/logging=Logger=utils/logging/mock_logger.go
github.com/ava-labs/avalanchego/utils/resource=User=utils/resource/mock_user.go
github.com/ava-labs/avalanchego/vms/avm/block=Block=vms/avm/block/mock_block.go
github.com/ava-labs/avalanchego/vms/avm/metrics=Metrics=vms/avm/metrics/mock_metrics.go
Expand Down
246 changes: 0 additions & 246 deletions utils/logging/mock_logger.go

This file was deleted.

12 changes: 1 addition & 11 deletions vms/registry/vm_registerer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ type vmRegistererTestResources struct {
ctrl *gomock.Controller
mockManager *vms.MockManager
mockServer *server.MockServer
mockLogger *logging.MockLogger
registerer VMRegisterer
}

Expand All @@ -420,27 +419,18 @@ func initRegistererTest(t *testing.T) *vmRegistererTestResources {

mockManager := vms.NewMockManager(ctrl)
mockServer := server.NewMockServer(ctrl)
mockLog := logging.NewMockLogger(ctrl)

registerer := NewVMRegisterer(VMRegistererConfig{
APIServer: mockServer,
Log: mockLog,
Log: logging.NoLog{},
VMFactoryLog: logging.NoLog{},
VMManager: mockManager,
})

mockLog.EXPECT().Error(gomock.Any(), gomock.Any()).AnyTimes()
mockLog.EXPECT().Warn(gomock.Any(), gomock.Any()).AnyTimes()
mockLog.EXPECT().Info(gomock.Any(), gomock.Any()).AnyTimes()
mockLog.EXPECT().Debug(gomock.Any(), gomock.Any()).AnyTimes()
mockLog.EXPECT().Trace(gomock.Any(), gomock.Any()).AnyTimes()
mockLog.EXPECT().Verbo(gomock.Any(), gomock.Any()).AnyTimes()

return &vmRegistererTestResources{
ctrl: ctrl,
mockManager: mockManager,
mockServer: mockServer,
mockLogger: mockLog,
registerer: registerer,
}
}
Loading