From ccf74d44eee60626fba19528f5c2f61eb5834ce5 Mon Sep 17 00:00:00 2001 From: Lisa Rashidi-Ranjbar Date: Tue, 10 Jun 2025 16:18:19 -0700 Subject: [PATCH] remove fsnotify from TestMonitorLocalStatus --- generate.go | 1 - .../mock_workceptor/workunitbase.go | 111 ------------------ pkg/workceptor/workunitbase_test.go | 45 ++----- 3 files changed, 11 insertions(+), 146 deletions(-) delete mode 100644 pkg/workceptor/mock_workceptor/workunitbase.go diff --git a/generate.go b/generate.go index e3de8cca5..1d59b9197 100644 --- a/generate.go +++ b/generate.go @@ -21,5 +21,4 @@ package main //go:generate mockgen -source=pkg/workceptor/kubernetes.go -destination=pkg/workceptor/mock_workceptor/kubernetes.go //go:generate mockgen -source=pkg/workceptor/stdio_utils.go -destination=pkg/workceptor/mock_workceptor/stdio_utils.go //go:generate mockgen -source=pkg/workceptor/workceptor.go -destination=pkg/workceptor/mock_workceptor/workceptor.go -//go:generate mockgen -source=pkg/workceptor/workunitbase.go -destination=pkg/workceptor/mock_workceptor/workunitbase.go //go:generate mockgen -package=mock_utils -destination=pkg/utils/mock_utils/io.go io ReadWriteCloser diff --git a/pkg/workceptor/mock_workceptor/workunitbase.go b/pkg/workceptor/mock_workceptor/workunitbase.go deleted file mode 100644 index 4e72c5466..000000000 --- a/pkg/workceptor/mock_workceptor/workunitbase.go +++ /dev/null @@ -1,111 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: pkg/workceptor/workunitbase.go -// -// Generated by this command: -// -// mockgen -source=pkg/workceptor/workunitbase.go -destination=pkg/workceptor/mock_workceptor/workunitbase.go -// - -// Package mock_workceptor is a generated GoMock package. -package mock_workceptor - -import ( - reflect "reflect" - - fsnotify "github.com/fsnotify/fsnotify" - gomock "go.uber.org/mock/gomock" -) - -// MockWatcherWrapper is a mock of WatcherWrapper interface. -type MockWatcherWrapper struct { - ctrl *gomock.Controller - recorder *MockWatcherWrapperMockRecorder - isgomock struct{} -} - -// MockWatcherWrapperMockRecorder is the mock recorder for MockWatcherWrapper. -type MockWatcherWrapperMockRecorder struct { - mock *MockWatcherWrapper -} - -// NewMockWatcherWrapper creates a new mock instance. -func NewMockWatcherWrapper(ctrl *gomock.Controller) *MockWatcherWrapper { - mock := &MockWatcherWrapper{ctrl: ctrl} - mock.recorder = &MockWatcherWrapperMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockWatcherWrapper) EXPECT() *MockWatcherWrapperMockRecorder { - return m.recorder -} - -// Add mocks base method. -func (m *MockWatcherWrapper) Add(name string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Add", name) - ret0, _ := ret[0].(error) - return ret0 -} - -// Add indicates an expected call of Add. -func (mr *MockWatcherWrapperMockRecorder) Add(name any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Add", reflect.TypeOf((*MockWatcherWrapper)(nil).Add), name) -} - -// Close mocks base method. -func (m *MockWatcherWrapper) Close() error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Close") - ret0, _ := ret[0].(error) - return ret0 -} - -// Close indicates an expected call of Close. -func (mr *MockWatcherWrapperMockRecorder) Close() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockWatcherWrapper)(nil).Close)) -} - -// ErrorChannel mocks base method. -func (m *MockWatcherWrapper) ErrorChannel() chan error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ErrorChannel") - ret0, _ := ret[0].(chan error) - return ret0 -} - -// ErrorChannel indicates an expected call of ErrorChannel. -func (mr *MockWatcherWrapperMockRecorder) ErrorChannel() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ErrorChannel", reflect.TypeOf((*MockWatcherWrapper)(nil).ErrorChannel)) -} - -// EventChannel mocks base method. -func (m *MockWatcherWrapper) EventChannel() chan fsnotify.Event { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EventChannel") - ret0, _ := ret[0].(chan fsnotify.Event) - return ret0 -} - -// EventChannel indicates an expected call of EventChannel. -func (mr *MockWatcherWrapperMockRecorder) EventChannel() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EventChannel", reflect.TypeOf((*MockWatcherWrapper)(nil).EventChannel)) -} - -// Remove mocks base method. -func (m *MockWatcherWrapper) Remove(path string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Remove", path) - ret0, _ := ret[0].(error) - return ret0 -} - -// Remove indicates an expected call of Remove. -func (mr *MockWatcherWrapperMockRecorder) Remove(path any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Remove", reflect.TypeOf((*MockWatcherWrapper)(nil).Remove), path) -} diff --git a/pkg/workceptor/workunitbase_test.go b/pkg/workceptor/workunitbase_test.go index 5f0d12ce0..fb3d28d0b 100644 --- a/pkg/workceptor/workunitbase_test.go +++ b/pkg/workceptor/workunitbase_test.go @@ -307,15 +307,6 @@ func TestMonitorLocalStatus(t *testing.T) { logOutput string sleepDuration time.Duration }{ - { - name: "Error Adding Watcher", - statObj: NewInfo("test", 1, 0, time.Now()), - addWatcherErr: fmt.Errorf("error adding watcher"), - statErr: nil, - fsNotifyEvent: nil, - logOutput: "", - sleepDuration: 100 * time.Millisecond, - }, { name: "Error Reading Status", statObj: nil, @@ -334,7 +325,6 @@ func TestMonitorLocalStatus(t *testing.T) { randstring := randstr.RandomString(4) logFilePath := fmt.Sprintf("/tmp/monitorLocalStatusLog%s", randstring) - mockWatcher := mock_workceptor.NewMockWatcherWrapper(ctrl) mockFileSystem := mock_workceptor.NewMockFileSystemer(ctrl) bwu.Init(w, "test", "", mockFileSystem) @@ -342,34 +332,21 @@ func TestMonitorLocalStatus(t *testing.T) { if tc.statObjLater != nil { mockFileSystem.EXPECT().Stat(gomock.Any()).Return(tc.statObjLater, nil).AnyTimes() } - mockWatcher.EXPECT().Remove(gomock.Any()).AnyTimes() - mockWatcher.EXPECT().Close().AnyTimes() - - if tc.fsNotifyEvent != nil { - logFile, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o600) - if err != nil { - t.Error("error creating monitorLocalStatusLog file") - } - l.SetOutput(logFile) - eventCh := make(chan fsnotify.Event, 1) - mockWatcher.EXPECT().EventChannel().Return(eventCh).AnyTimes() - go func() { eventCh <- *tc.fsNotifyEvent }() - - errorCh := make(chan error, 1) - mockWatcher.EXPECT().ErrorChannel().Return(errorCh).AnyTimes() + + logFile, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o600) + if err != nil { + t.Error("error creating monitorLocalStatusLog file") } + l.SetOutput(logFile) go bwu.MonitorLocalStatus() time.Sleep(tc.sleepDuration) - - if tc.fsNotifyEvent != nil { - logOutput, err := os.ReadFile(logFilePath) - if err != nil && len(logOutput) == 0 { - t.Errorf("error reading %s file", logFilePath) - } - if !bytes.Contains(logOutput, []byte(tc.logOutput)) { - t.Errorf("expected log to be: %s, got %s", tc.logOutput, string(logOutput)) - } + logOutput, err := os.ReadFile(logFilePath) + if err != nil && len(logOutput) == 0 { + t.Errorf("error reading %s file", logFilePath) + } + if !bytes.Contains(logOutput, []byte(tc.logOutput)) { + t.Errorf("expected log to be: %s, got %s", tc.logOutput, string(logOutput)) } bwu.CancelContext()