diff --git a/agent/eni/networkutils/mocks/utils_windows.go b/agent/eni/networkutils/mocks/utils_windows.go new file mode 100644 index 00000000000..20cc4390f6b --- /dev/null +++ b/agent/eni/networkutils/mocks/utils_windows.go @@ -0,0 +1,96 @@ +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. +// + +// Code generated by MockGen. DO NOT EDIT. +// Source: ./utils.go + +// Package mock_networkutils is a generated GoMock package. +package mock_networkutils + +import ( + context "context" + net "net" + reflect "reflect" + time "time" + + gomock "github.com/golang/mock/gomock" +) + +// MockNetworkUtils is a mock of NetworkUtils interface +type MockNetworkUtils struct { + ctrl *gomock.Controller + recorder *MockNetworkUtilsMockRecorder +} + +// MockNetworkUtilsMockRecorder is the mock recorder for MockNetworkUtils +type MockNetworkUtilsMockRecorder struct { + mock *MockNetworkUtils +} + +// NewMockNetworkUtils creates a new mock instance +func NewMockNetworkUtils(ctrl *gomock.Controller) *MockNetworkUtils { + mock := &MockNetworkUtils{ctrl: ctrl} + mock.recorder = &MockNetworkUtilsMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockNetworkUtils) EXPECT() *MockNetworkUtilsMockRecorder { + return m.recorder +} + +// GetInterfaceMACByIndex mocks base method +func (m *MockNetworkUtils) GetInterfaceMACByIndex(arg0 int, arg1 context.Context, arg2 time.Duration) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetInterfaceMACByIndex", arg0, arg1, arg2) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetInterfaceMACByIndex indicates an expected call of GetInterfaceMACByIndex +func (mr *MockNetworkUtilsMockRecorder) GetInterfaceMACByIndex(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInterfaceMACByIndex", reflect.TypeOf((*MockNetworkUtils)(nil).GetInterfaceMACByIndex), arg0, arg1, arg2) +} + +// GetAllNetworkInterfaces mocks base method +func (m *MockNetworkUtils) GetAllNetworkInterfaces() ([]net.Interface, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllNetworkInterfaces") + ret0, _ := ret[0].([]net.Interface) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAllNetworkInterfaces indicates an expected call of GetAllNetworkInterfaces +func (mr *MockNetworkUtilsMockRecorder) GetAllNetworkInterfaces() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllNetworkInterfaces", reflect.TypeOf((*MockNetworkUtils)(nil).GetAllNetworkInterfaces)) +} + +// GetDNSServerAddressList mocks base method +func (m *MockNetworkUtils) GetDNSServerAddressList(macAddress string) ([]string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetDNSServerAddressList", macAddress) + ret0, _ := ret[0].([]string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetDNSServerAddressList indicates an expected call of GetDNSServerAddressList +func (mr *MockNetworkUtilsMockRecorder) GetDNSServerAddressList(macAddress interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDNSServerAddressList", reflect.TypeOf((*MockNetworkUtils)(nil).GetDNSServerAddressList), macAddress) +} diff --git a/agent/eni/networkutils/utils_windows.go b/agent/eni/networkutils/utils_windows.go index 4c4e68d3d91..2f8cf299539 100644 --- a/agent/eni/networkutils/utils_windows.go +++ b/agent/eni/networkutils/utils_windows.go @@ -25,22 +25,23 @@ import ( "time" "unsafe" - "golang.org/x/sys/windows" - apierrors "github.com/aws/amazon-ecs-agent/agent/api/errors" "github.com/aws/amazon-ecs-agent/agent/eni/netwrapper" "github.com/aws/amazon-ecs-agent/agent/utils/retry" + "github.com/cihub/seelog" "github.com/pkg/errors" + "golang.org/x/sys/windows" ) +//go:generate mockgen -destination=mocks/$GOFILE -copyright_file=../../../scripts/copyright_file github.com/aws/amazon-ecs-agent/agent/eni/networkutils NetworkUtils + // NetworkUtils is the interface used for accessing network related functionality on Windows. // The methods declared in this package may or may not add any additional logic over the actual networking api calls. type NetworkUtils interface { GetInterfaceMACByIndex(int, context.Context, time.Duration) (string, error) GetAllNetworkInterfaces() ([]net.Interface, error) GetDNSServerAddressList(macAddress string) ([]string, error) - SetNetWrapper(netWrapper netwrapper.NetWrapper) } type networkUtils struct { @@ -118,11 +119,6 @@ func (utils *networkUtils) GetAllNetworkInterfaces() ([]net.Interface, error) { return utils.netWrapper.GetAllNetworkInterfaces() } -// SetNetWrapper is used to inject netWrapper instance. This will be handy while testing to inject mocks. -func (utils *networkUtils) SetNetWrapper(netWrapper netwrapper.NetWrapper) { - utils.netWrapper = netWrapper -} - // GetDNSServerAddressList returns the DNS server addresses of the queried interface. func (utils *networkUtils) GetDNSServerAddressList(macAddress string) ([]string, error) { addresses, err := funcGetAdapterAddresses() @@ -141,7 +137,7 @@ func (utils *networkUtils) GetDNSServerAddressList(macAddress string) ([]string, dnsServerAddressList := make([]string, 0) for firstDnsNode != nil { - dnsServerAddressList = append(dnsServerAddressList, utils.parseSocketAddress(firstDnsNode.Address)) + dnsServerAddressList = append(dnsServerAddressList, firstDnsNode.Address.IP().String()) firstDnsNode = firstDnsNode.Next } @@ -158,18 +154,6 @@ func (utils *networkUtils) parseMACAddress(adapterAddress *windows.IpAdapterAddr return hardwareAddr } -// parseSocketAddress parses the SocketAddress into its string representation. -// This method needs to be deprecated in favour of IP() method of SocketAdress introduced in Go 1.13+. -// The method details have been taken from https://github.com/golang/sys/blob/release-branch.go1.13/windows/types_windows.go -func (utils *networkUtils) parseSocketAddress(addr windows.SocketAddress) string { - var ipAddr string - if uintptr(addr.SockaddrLength) >= unsafe.Sizeof(syscall.RawSockaddrInet4{}) && addr.Sockaddr.Addr.Family == syscall.AF_INET { - ip := net.IP((*syscall.RawSockaddrInet4)(unsafe.Pointer(addr.Sockaddr)).Addr[:]) - ipAddr = ip.String() - } - return ipAddr -} - // getAdapterAddresses returns a list of IP adapter and address // structures. The structure contains an IP adapter and flattened // multiple IP addresses including unicast, anycast and multicast diff --git a/agent/eni/networkutils/utils_windows_test.go b/agent/eni/networkutils/utils_windows_test.go index 755ccb353cd..65075ad00cc 100644 --- a/agent/eni/networkutils/utils_windows_test.go +++ b/agent/eni/networkutils/utils_windows_test.go @@ -44,8 +44,7 @@ func TestGetInterfaceMACByIndex(t *testing.T) { ctx := context.TODO() mocknetwrapper := mock_netwrapper.NewMockNetWrapper(mockCtrl) - netUtils := New() - netUtils.SetNetWrapper(mocknetwrapper) + netUtils := &networkUtils{netWrapper: mocknetwrapper} hardwareAddr, err := net.ParseMAC(macAddress) mocknetwrapper.EXPECT().FindInterfaceByIndex(interfaceIndex).Return( @@ -68,8 +67,7 @@ func TestGetInterfaceMACByIndexEmptyAddress(t *testing.T) { ctx := context.TODO() mocknetwrapper := mock_netwrapper.NewMockNetWrapper(mockCtrl) - netUtils := New() - netUtils.SetNetWrapper(mocknetwrapper) + netUtils := &networkUtils{netWrapper: mocknetwrapper} mocknetwrapper.EXPECT().FindInterfaceByIndex(interfaceIndex).Return( &net.Interface{ @@ -91,8 +89,7 @@ func TestGetInterfaceMACByIndexRetries(t *testing.T) { ctx := context.TODO() mocknetwrapper := mock_netwrapper.NewMockNetWrapper(mockCtrl) - netUtils := New() - netUtils.SetNetWrapper(mocknetwrapper) + netUtils := &networkUtils{netWrapper: mocknetwrapper} hardwareAddr, err := net.ParseMAC(macAddress) emptyaddr := make([]byte, 0) @@ -123,8 +120,7 @@ func TestGetInterfaceMACByIndexContextTimeout(t *testing.T) { ctx := context.TODO() mocknetwrapper := mock_netwrapper.NewMockNetWrapper(mockCtrl) - netUtils := New() - netUtils.SetNetWrapper(mocknetwrapper) + netUtils := &networkUtils{netWrapper: mocknetwrapper} mocknetwrapper.EXPECT().FindInterfaceByIndex(interfaceIndex).Return( &net.Interface{ @@ -146,8 +142,7 @@ func TestGetInterfaceMACByIndexWithGolangNetError(t *testing.T) { ctx := context.TODO() mocknetwrapper := mock_netwrapper.NewMockNetWrapper(mockCtrl) - netUtils := New() - netUtils.SetNetWrapper(mocknetwrapper) + netUtils := &networkUtils{netWrapper: mocknetwrapper} mocknetwrapper.EXPECT().FindInterfaceByIndex(interfaceIndex).Return( nil, errors.New("unable to retrieve interface")) @@ -164,8 +159,7 @@ func TestGetAllNetworkInterfaces(t *testing.T) { defer mockCtrl.Finish() mocknetwrapper := mock_netwrapper.NewMockNetWrapper(mockCtrl) - netUtils := New() - netUtils.SetNetWrapper(mocknetwrapper) + netUtils := &networkUtils{netWrapper: mocknetwrapper} expectedIface := make([]net.Interface, 1) @@ -191,8 +185,7 @@ func TestGetAllNetworkInterfacesError(t *testing.T) { defer mockCtrl.Finish() mocknetwrapper := mock_netwrapper.NewMockNetWrapper(mockCtrl) - netUtils := New() - netUtils.SetNetWrapper(mocknetwrapper) + netUtils := &networkUtils{netWrapper: mocknetwrapper} mocknetwrapper.EXPECT().GetAllNetworkInterfaces().Return( nil, errors.New("error occurred while fetching interfaces"), diff --git a/agent/eni/watcher/watcher_windows.go b/agent/eni/watcher/watcher_windows.go index 04e6a1fddba..50ec7baa75e 100644 --- a/agent/eni/watcher/watcher_windows.go +++ b/agent/eni/watcher/watcher_windows.go @@ -59,8 +59,6 @@ func newWatcher(ctx context.Context, state dockerstate.TaskEngineState, stateChangeEvents chan<- statechange.Event) (*ENIWatcher, error) { - derivedContext, cancel := context.WithCancel(ctx) - eniMonitor := iphelperwrapper.NewMonitor() notificationChannel := make(chan int) err := eniMonitor.Start(notificationChannel) @@ -69,6 +67,7 @@ func newWatcher(ctx context.Context, } log.Info("windows eni watcher has been initialized") + derivedContext, cancel := context.WithCancel(ctx) return &ENIWatcher{ ctx: derivedContext, cancel: cancel, @@ -172,9 +171,3 @@ func (eniWatcher *ENIWatcher) getAllInterfaces() (state map[string]int, err erro } return state, nil } - -// SetNetworkUtils is used for injecting NetworkUtils instance in eniWatcher -// This will be handy while testing to inject mock objects -func (eniWatcher *ENIWatcher) SetNetworkUtils(utils networkutils.NetworkUtils) { - eniWatcher.netutils = utils -} diff --git a/agent/eni/watcher/watcher_windows_test.go b/agent/eni/watcher/watcher_windows_test.go index 8313d07e8b2..af2eb1ac52d 100644 --- a/agent/eni/watcher/watcher_windows_test.go +++ b/agent/eni/watcher/watcher_windows_test.go @@ -18,7 +18,6 @@ package watcher import ( "context" - "net" "sync" "testing" @@ -30,9 +29,9 @@ import ( mock_dockerstate "github.com/aws/amazon-ecs-agent/agent/engine/dockerstate/mocks" "github.com/aws/amazon-ecs-agent/agent/eni/iphelperwrapper" mock_iphelperwrapper "github.com/aws/amazon-ecs-agent/agent/eni/iphelperwrapper/mocks" - "github.com/aws/amazon-ecs-agent/agent/eni/networkutils" - mock_gonetwrapper "github.com/aws/amazon-ecs-agent/agent/eni/netwrapper/mocks" + mock_networkutils "github.com/aws/amazon-ecs-agent/agent/eni/networkutils/mocks" "github.com/aws/amazon-ecs-agent/agent/statechange" + "github.com/golang/mock/gomock" "github.com/pkg/errors" "github.com/stretchr/testify/assert" @@ -82,7 +81,6 @@ func constructInterfaceList() []net.Interface { // newTestWatcher is used to create a watcher for testing purpose func newTestWatcher(ctx context.Context, primaryMAC string, state dockerstate.TaskEngineState, stateChangeEvents chan<- statechange.Event, eniMonitor iphelperwrapper.InterfaceMonitor) (*ENIWatcher, error) { - derivedContext, cancel := context.WithCancel(ctx) notificationChannel := make(chan int) err := eniMonitor.Start(notificationChannel) @@ -90,6 +88,7 @@ func newTestWatcher(ctx context.Context, primaryMAC string, state dockerstate.Ta return nil, errors.Wrapf(err, "error occurred while instantiating watcher") } + derivedContext, cancel := context.WithCancel(ctx) return &ENIWatcher{ ctx: derivedContext, cancel: cancel, @@ -98,7 +97,6 @@ func newTestWatcher(ctx context.Context, primaryMAC string, state dockerstate.Ta primaryMAC: primaryMAC, interfaceMonitor: eniMonitor, notifications: notificationChannel, - netutils: networkutils.New(), }, nil } @@ -164,13 +162,11 @@ func TestReconcileOnce(t *testing.T) { }, true) mockiphelper := mock_iphelperwrapper.NewMockInterfaceMonitor(mockCtrl) mockiphelper.EXPECT().Start(gomock.Any()).Return(nil) - mocknetwrapper := mock_gonetwrapper.NewMockNetWrapper(mockCtrl) - mocknetwrapper.EXPECT().GetAllNetworkInterfaces().Return(constructInterfaceList(), nil) + mockNetworkUtils := mock_networkutils.NewMockNetworkUtils(mockCtrl) + mockNetworkUtils.EXPECT().GetAllNetworkInterfaces().Return(constructInterfaceList(), nil) watcher, _ := newTestWatcher(ctx, primaryMAC, mockStateManager, eventChannel, mockiphelper) - netutils := networkutils.New() - netutils.SetNetWrapper(mocknetwrapper) - watcher.SetNetworkUtils(netutils) + watcher.netutils = mockNetworkUtils waitForEvents.Add(2) @@ -204,13 +200,11 @@ func TestReconcileOnceNetUtilsError(t *testing.T) { mockiphelper := mock_iphelperwrapper.NewMockInterfaceMonitor(mockCtrl) mockiphelper.EXPECT().Start(gomock.Any()).Return(nil) - mocknetwrapper := mock_gonetwrapper.NewMockNetWrapper(mockCtrl) - mocknetwrapper.EXPECT().GetAllNetworkInterfaces().Return(nil, errors.New("Error while retrieving interfaces")) + mockNetworkUtils := mock_networkutils.NewMockNetworkUtils(mockCtrl) + mockNetworkUtils.EXPECT().GetAllNetworkInterfaces().Return(nil, errors.New("Error while retrieving interfaces")) watcher, _ := newTestWatcher(ctx, primaryMAC, nil, eventChannel, mockiphelper) - netutils := networkutils.New() - netutils.SetNetWrapper(mocknetwrapper) - watcher.SetNetworkUtils(netutils) + watcher.netutils = mockNetworkUtils err := watcher.Init() assert.Error(t, err) @@ -227,13 +221,11 @@ func TestReconcileOnceEmptyInterfaceList(t *testing.T) { mockiphelper := mock_iphelperwrapper.NewMockInterfaceMonitor(mockCtrl) mockiphelper.EXPECT().Start(gomock.Any()).Return(nil) - mocknetwrapper := mock_gonetwrapper.NewMockNetWrapper(mockCtrl) - mocknetwrapper.EXPECT().GetAllNetworkInterfaces().Return(make([]net.Interface, 0), nil) + mockNetworkUtils := mock_networkutils.NewMockNetworkUtils(mockCtrl) + mockNetworkUtils.EXPECT().GetAllNetworkInterfaces().Return(make([]net.Interface, 0), nil) watcher, _ := newTestWatcher(ctx, primaryMAC, nil, eventChannel, mockiphelper) - netutils := networkutils.New() - netutils.SetNetWrapper(mocknetwrapper) - watcher.SetNetworkUtils(netutils) + watcher.netutils = mockNetworkUtils err := watcher.Init() assert.NoError(t, err) @@ -252,17 +244,12 @@ func TestEventHandlerSuccess(t *testing.T) { eventChannel := make(chan statechange.Event) mockiphelper := mock_iphelperwrapper.NewMockInterfaceMonitor(mockCtrl) - mocknetwrapper := mock_gonetwrapper.NewMockNetWrapper(mockCtrl) mockStateManager := mock_dockerstate.NewMockTaskEngineState(mockCtrl) + mockNetworkUtils := mock_networkutils.NewMockNetworkUtils(mockCtrl) - mac1, _ := net.ParseMAC(macAddress1) gomock.InOrder( mockiphelper.EXPECT().Start(gomock.Any()).Return(nil), - mocknetwrapper.EXPECT().FindInterfaceByIndex(interfaceIndex1).Return(&net.Interface{ - Index: interfaceIndex1, - Name: interfacename1, - HardwareAddr: mac1, - }, nil), + mockNetworkUtils.EXPECT().GetInterfaceMACByIndex(interfaceIndex1, gomock.Any(), sendENIStateChangeRetryTimeout).Return(macAddress1, nil), mockStateManager.EXPECT().ENIByMac(macAddress1). Return(&apieni.ENIAttachment{ MACAddress: macAddress1, @@ -271,9 +258,7 @@ func TestEventHandlerSuccess(t *testing.T) { ) watcher, _ := newTestWatcher(ctx, primaryMAC, mockStateManager, eventChannel, mockiphelper) - netutils := networkutils.New() - netutils.SetNetWrapper(mocknetwrapper) - watcher.SetNetworkUtils(netutils) + watcher.netutils = mockNetworkUtils go watcher.eventHandler() watcher.notifications <- interfaceIndex1 @@ -310,17 +295,16 @@ func TestEventHandlerGetInterfaceByMACError(t *testing.T) { eventChannel := make(chan statechange.Event) mockiphelper := mock_iphelperwrapper.NewMockInterfaceMonitor(mockCtrl) - mocknetwrapper := mock_gonetwrapper.NewMockNetWrapper(mockCtrl) + mockNetworkUtils := mock_networkutils.NewMockNetworkUtils(mockCtrl) gomock.InOrder( mockiphelper.EXPECT().Start(gomock.Any()).Return(nil), - mocknetwrapper.EXPECT().FindInterfaceByIndex(gomock.Any()).Return(nil, errors.New("Error while retrieving details")), + mockNetworkUtils.EXPECT().GetInterfaceMACByIndex(interfaceIndex1, gomock.Any(), sendENIStateChangeRetryTimeout).Return( + "", errors.New("Error while retrieving details")), ) watcher, _ := newTestWatcher(ctx, primaryMAC, nil, eventChannel, mockiphelper) - netutils := networkutils.New() - netutils.SetNetWrapper(mocknetwrapper) - watcher.SetNetworkUtils(netutils) + watcher.netutils = mockNetworkUtils go watcher.eventHandler() watcher.notifications <- interfaceIndex1 @@ -348,17 +332,12 @@ func TestEventHandlerENIStatusAlreadySent(t *testing.T) { eventChannel := make(chan statechange.Event) mockiphelper := mock_iphelperwrapper.NewMockInterfaceMonitor(mockCtrl) - mocknetwrapper := mock_gonetwrapper.NewMockNetWrapper(mockCtrl) mockStateManager := mock_dockerstate.NewMockTaskEngineState(mockCtrl) + mockNetworkUtils := mock_networkutils.NewMockNetworkUtils(mockCtrl) - mac1, _ := net.ParseMAC(macAddress1) gomock.InOrder( mockiphelper.EXPECT().Start(gomock.Any()).Return(nil), - mocknetwrapper.EXPECT().FindInterfaceByIndex(interfaceIndex1).Return(&net.Interface{ - Index: interfaceIndex1, - Name: interfacename1, - HardwareAddr: mac1, - }, nil), + mockNetworkUtils.EXPECT().GetInterfaceMACByIndex(interfaceIndex1, gomock.Any(), sendENIStateChangeRetryTimeout).Return(macAddress1, nil), mockStateManager.EXPECT().ENIByMac(macAddress1). Return(&apieni.ENIAttachment{ MACAddress: macAddress1, @@ -367,9 +346,7 @@ func TestEventHandlerENIStatusAlreadySent(t *testing.T) { ) watcher, _ := newTestWatcher(ctx, primaryMAC, mockStateManager, eventChannel, mockiphelper) - netutils := networkutils.New() - netutils.SetNetWrapper(mocknetwrapper) - watcher.SetNetworkUtils(netutils) + watcher.netutils = mockNetworkUtils go watcher.eventHandler() watcher.notifications <- interfaceIndex1 @@ -397,25 +374,18 @@ func TestEventHandlerUnmanagedENI(t *testing.T) { eventChannel := make(chan statechange.Event) mockiphelper := mock_iphelperwrapper.NewMockInterfaceMonitor(mockCtrl) - mocknetwrapper := mock_gonetwrapper.NewMockNetWrapper(mockCtrl) mockStateManager := mock_dockerstate.NewMockTaskEngineState(mockCtrl) + mockNetworkUtils := mock_networkutils.NewMockNetworkUtils(mockCtrl) - mac1, _ := net.ParseMAC(macAddress1) gomock.InOrder( mockiphelper.EXPECT().Start(gomock.Any()).Return(nil), - mocknetwrapper.EXPECT().FindInterfaceByIndex(interfaceIndex1).Return(&net.Interface{ - Index: interfaceIndex1, - Name: interfacename1, - HardwareAddr: mac1, - }, nil), + mockNetworkUtils.EXPECT().GetInterfaceMACByIndex(interfaceIndex1, gomock.Any(), sendENIStateChangeRetryTimeout).Return(macAddress1, nil), mockStateManager.EXPECT().ENIByMac(macAddress1). Return(nil, false).AnyTimes(), ) watcher, _ := newTestWatcher(ctx, primaryMAC, mockStateManager, eventChannel, mockiphelper) - netutils := networkutils.New() - netutils.SetNetWrapper(mocknetwrapper) - watcher.SetNetworkUtils(netutils) + watcher.netutils = mockNetworkUtils go watcher.eventHandler() watcher.notifications <- interfaceIndex1 @@ -443,17 +413,12 @@ func TestEventHandlerExpiredENI(t *testing.T) { eventChannel := make(chan statechange.Event) mockiphelper := mock_iphelperwrapper.NewMockInterfaceMonitor(mockCtrl) - mocknetwrapper := mock_gonetwrapper.NewMockNetWrapper(mockCtrl) mockStateManager := mock_dockerstate.NewMockTaskEngineState(mockCtrl) + mockNetworkUtils := mock_networkutils.NewMockNetworkUtils(mockCtrl) - mac1, _ := net.ParseMAC(macAddress1) gomock.InOrder( mockiphelper.EXPECT().Start(gomock.Any()).Return(nil), - mocknetwrapper.EXPECT().FindInterfaceByIndex(interfaceIndex1).Return(&net.Interface{ - Index: interfaceIndex1, - Name: interfacename1, - HardwareAddr: mac1, - }, nil), + mockNetworkUtils.EXPECT().GetInterfaceMACByIndex(interfaceIndex1, gomock.Any(), sendENIStateChangeRetryTimeout).Return(macAddress1, nil), mockStateManager.EXPECT().ENIByMac(macAddress1). Return(&apieni.ENIAttachment{ MACAddress: macAddress1, @@ -463,9 +428,7 @@ func TestEventHandlerExpiredENI(t *testing.T) { ) watcher, _ := newTestWatcher(ctx, primaryMAC, mockStateManager, eventChannel, mockiphelper) - netutils := networkutils.New() - netutils.SetNetWrapper(mocknetwrapper) - watcher.SetNetworkUtils(netutils) + watcher.netutils = mockNetworkUtils go watcher.eventHandler() watcher.notifications <- interfaceIndex1