From a5d3c141f07e255f74f23179b9758c872fa54708 Mon Sep 17 00:00:00 2001 From: Mansur Uralov Date: Wed, 10 Jan 2024 09:14:48 +0100 Subject: [PATCH 1/3] Enable goerr113 linting for EventMesh tests --- internal/controller/operator/eventing/eventmesh_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/controller/operator/eventing/eventmesh_test.go b/internal/controller/operator/eventing/eventmesh_test.go index 2b72cd24..405268f1 100644 --- a/internal/controller/operator/eventing/eventmesh_test.go +++ b/internal/controller/operator/eventing/eventmesh_test.go @@ -37,7 +37,6 @@ var ( errNotFound = errors.New("secret not found") ) -//nolint:goerr113 // all tests here need to be fixed, as they use require.ErrorAs and use it wrongly func Test_reconcileEventMeshSubManager(t *testing.T) { t.Parallel() From 114739791600fd643424b0a98672e97f803349b1 Mon Sep 17 00:00:00 2001 From: Mansur Uralov Date: Wed, 10 Jan 2024 09:50:56 +0100 Subject: [PATCH 2/3] Fix linting errors --- .../operator/eventing/eventmesh_test.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/controller/operator/eventing/eventmesh_test.go b/internal/controller/operator/eventing/eventmesh_test.go index 405268f1..872d1bb4 100644 --- a/internal/controller/operator/eventing/eventmesh_test.go +++ b/internal/controller/operator/eventing/eventmesh_test.go @@ -31,10 +31,12 @@ const ( ) var ( - ErrFailedToStart = errors.New("failed to start") - ErrFailedToStop = errors.New("failed to stop") - ErrFailedToRemove = errors.New("failed to remove") - errNotFound = errors.New("secret not found") + ErrFailedToStart = errors.New("failed to start") + ErrFailedToStop = errors.New("failed to stop") + ErrFailedToRemove = errors.New("failed to remove") + errNotFound = errors.New("secret not found") + ErrFailedToApplyPatch = errors.New("failed to apply patch") + ErrFailedToSyncEPPSecret = errors.New("failed to sync Publisher Proxy secret: failed to apply patch") ) func Test_reconcileEventMeshSubManager(t *testing.T) { @@ -123,10 +125,10 @@ func Test_reconcileEventMeshSubManager(t *testing.T) { mockKubeClient := new(k8smocks.Client) mockKubeClient.On("GetSecret", ctx, mock.Anything, mock.Anything).Return( utils.NewOAuthSecret("test-secret", givenEventing.Namespace), nil).Once() - mockKubeClient.On("PatchApply", ctx, mock.Anything).Return(errors.New("failed to apply patch")).Once() + mockKubeClient.On("PatchApply", ctx, mock.Anything).Return(ErrFailedToApplyPatch).Once() return mockKubeClient }, - wantError: errors.New("failed to sync Publisher Proxy secret: failed to apply patch"), + wantError: ErrFailedToSyncEPPSecret, }, { name: "it should do nothing because subscription manager is already started", @@ -195,7 +197,7 @@ func Test_reconcileEventMeshSubManager(t *testing.T) { givenEventMeshSubManagerMock: func() *submgrmanagermocks.Manager { eventMeshSubManagerMock := new(submgrmanagermocks.Manager) eventMeshSubManagerMock.On("Init", mock.Anything).Return(nil).Once() - eventMeshSubManagerMock.On("Start", mock.Anything, mock.Anything).Return(errors.New("failed to start")).Twice() + eventMeshSubManagerMock.On("Start", mock.Anything, mock.Anything).Return(ErrFailedToStart).Twice() return eventMeshSubManagerMock }, givenEventingManagerMock: func() *eventingmocks.Manager { @@ -217,7 +219,7 @@ func Test_reconcileEventMeshSubManager(t *testing.T) { }, wantAssertCheck: true, givenShouldRetry: true, - wantError: errors.New("failed to start"), + wantError: ErrFailedToStart, wantHashAfter: int64(0), }, { From cb6fd9a352fef283e3312dd92b30209243bc2e2b Mon Sep 17 00:00:00 2001 From: Mansur Uralov Date: Thu, 11 Jan 2024 10:00:40 +0100 Subject: [PATCH 3/3] Rename ErrFailedToSyncEPPSecret name --- .../controller/operator/eventing/eventmesh_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/controller/operator/eventing/eventmesh_test.go b/internal/controller/operator/eventing/eventmesh_test.go index 872d1bb4..5e9c7206 100644 --- a/internal/controller/operator/eventing/eventmesh_test.go +++ b/internal/controller/operator/eventing/eventmesh_test.go @@ -31,12 +31,12 @@ const ( ) var ( - ErrFailedToStart = errors.New("failed to start") - ErrFailedToStop = errors.New("failed to stop") - ErrFailedToRemove = errors.New("failed to remove") - errNotFound = errors.New("secret not found") - ErrFailedToApplyPatch = errors.New("failed to apply patch") - ErrFailedToSyncEPPSecret = errors.New("failed to sync Publisher Proxy secret: failed to apply patch") + ErrFailedToStart = errors.New("failed to start") + ErrFailedToStop = errors.New("failed to stop") + ErrFailedToRemove = errors.New("failed to remove") + errNotFound = errors.New("secret not found") + ErrFailedToApplyPatch = errors.New("failed to apply patch") + ErrFailedToSyncPPSecret = errors.New("failed to sync Publisher Proxy secret: failed to apply patch") ) func Test_reconcileEventMeshSubManager(t *testing.T) { @@ -128,7 +128,7 @@ func Test_reconcileEventMeshSubManager(t *testing.T) { mockKubeClient.On("PatchApply", ctx, mock.Anything).Return(ErrFailedToApplyPatch).Once() return mockKubeClient }, - wantError: ErrFailedToSyncEPPSecret, + wantError: ErrFailedToSyncPPSecret, }, { name: "it should do nothing because subscription manager is already started",