From ad7bd2a8607be78dd05970050d91a85589efa271 Mon Sep 17 00:00:00 2001 From: Rakesh Garimella Date: Mon, 5 Aug 2024 17:36:14 +0200 Subject: [PATCH 1/2] move from mocks to stubs --- .mockery.yaml | 7 -- .../reconciler/commonstatus/checker_test.go | 16 +-- .../commonstatus/stubs/daemon_set_prober.go | 20 ++++ .../stubs/deployment_set_prober.go | 20 ++++ .../logparser/mocks/daemon_set_prober.go | 48 --------- internal/reconciler/logparser/status_test.go | 9 +- .../logpipeline/mocks/daemon_set_prober.go | 48 --------- .../reconciler/logpipeline/reconciler_test.go | 42 +++----- .../metricpipeline/mocks/daemon_set_prober.go | 48 --------- .../metricpipeline/mocks/deployment_prober.go | 48 --------- .../metricpipeline/reconciler_test.go | 99 +++++++++---------- .../tracepipeline/mocks/deployment_prober.go | 48 --------- .../tracepipeline/reconciler_test.go | 40 +++----- 13 files changed, 122 insertions(+), 371 deletions(-) create mode 100644 internal/reconciler/commonstatus/stubs/daemon_set_prober.go create mode 100644 internal/reconciler/commonstatus/stubs/deployment_set_prober.go delete mode 100644 internal/reconciler/logparser/mocks/daemon_set_prober.go delete mode 100644 internal/reconciler/logpipeline/mocks/daemon_set_prober.go delete mode 100644 internal/reconciler/metricpipeline/mocks/daemon_set_prober.go delete mode 100644 internal/reconciler/metricpipeline/mocks/deployment_prober.go delete mode 100644 internal/reconciler/tracepipeline/mocks/deployment_prober.go diff --git a/.mockery.yaml b/.mockery.yaml index cd6ecbe73..4f8210309 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -6,20 +6,15 @@ dir: "{{.InterfaceDir}}/mocks/" mockname: "{{.InterfaceName | firstUpper}}" filename: "{{.InterfaceName | snakecase}}.go" packages: - github.com/kyma-project/telemetry-manager/internal/reconciler/logparser: - interfaces: - DaemonSetProber: github.com/kyma-project/telemetry-manager/internal/reconciler/logpipeline: interfaces: DaemonSetAnnotator: - DaemonSetProber: FlowHealthProber: IstioStatusChecker: OverridesHandler: ErrorToMessageConverter: github.com/kyma-project/telemetry-manager/internal/reconciler/tracepipeline: interfaces: - DeploymentProber: FlowHealthProber: GatewayApplierDeleter: GatewayConfigBuilder: @@ -31,8 +26,6 @@ packages: interfaces: AgentApplierDeleter: AgentConfigBuilder: - DaemonSetProber: - DeploymentProber: FlowHealthProber: GatewayApplierDeleter: GatewayConfigBuilder: diff --git a/internal/reconciler/commonstatus/checker_test.go b/internal/reconciler/commonstatus/checker_test.go index 969ed747e..1e9866201 100644 --- a/internal/reconciler/commonstatus/checker_test.go +++ b/internal/reconciler/commonstatus/checker_test.go @@ -3,6 +3,7 @@ package commonstatus import ( "context" "fmt" + "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" "testing" "github.com/stretchr/testify/require" @@ -10,9 +11,6 @@ import ( "k8s.io/apimachinery/pkg/types" "github.com/kyma-project/telemetry-manager/internal/conditions" - logMocks "github.com/kyma-project/telemetry-manager/internal/reconciler/logpipeline/mocks" - metricMocks "github.com/kyma-project/telemetry-manager/internal/reconciler/metricpipeline/mocks" - traceMocks "github.com/kyma-project/telemetry-manager/internal/reconciler/tracepipeline/mocks" "github.com/kyma-project/telemetry-manager/internal/workloadstatus" ) @@ -65,8 +63,7 @@ func TestTracesGetHealthCondition(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gatewayProberStub := &traceMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", context.TODO(), types.NamespacedName{}).Return(tt.proberErr) + gatewayProberStub := stubs.NewDeploymentSetProber(tt.proberErr) actualCondition := GetGatewayHealthyCondition(context.TODO(), gatewayProberStub, types.NamespacedName{}, &conditions.ErrorToMessageConverter{}, SignalTypeTraces) require.True(t, validateCondition(t, tt.expectedCondition, actualCondition)) }) @@ -153,10 +150,8 @@ func TestMetricsGetHealthCondition(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - agentProberStub := &metricMocks.DaemonSetProber{} - agentProberStub.On("IsReady", context.TODO(), types.NamespacedName{}).Return(tt.proberAgentErr) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", context.TODO(), types.NamespacedName{}).Return(tt.preberGatewayErr) + agentProberStub := stubs.NewDaemonSetProber(tt.proberAgentErr) + gatewayProberStub := stubs.NewDeploymentSetProber(tt.preberGatewayErr) actualAgentCondition := GetAgentHealthyCondition(context.TODO(), agentProberStub, types.NamespacedName{}, &conditions.ErrorToMessageConverter{}, SignalTypeMetrics) actualGatewayCondition := GetGatewayHealthyCondition(context.TODO(), gatewayProberStub, types.NamespacedName{}, &conditions.ErrorToMessageConverter{}, SignalTypeMetrics) @@ -216,8 +211,7 @@ func TestLogsGetHealthCondition(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - agentProberStub := &logMocks.DaemonSetProber{} - agentProberStub.On("IsReady", context.TODO(), types.NamespacedName{}).Return(tt.proberErr) + agentProberStub := stubs.NewDaemonSetProber(tt.proberErr) actualCondition := GetAgentHealthyCondition(context.TODO(), agentProberStub, types.NamespacedName{}, &conditions.ErrorToMessageConverter{}, SignalTypeLogs) require.True(t, validateCondition(t, tt.expectedCondition, actualCondition)) }) diff --git a/internal/reconciler/commonstatus/stubs/daemon_set_prober.go b/internal/reconciler/commonstatus/stubs/daemon_set_prober.go new file mode 100644 index 000000000..010cdf1b5 --- /dev/null +++ b/internal/reconciler/commonstatus/stubs/daemon_set_prober.go @@ -0,0 +1,20 @@ +package stubs + +import ( + "context" + "k8s.io/apimachinery/pkg/types" +) + +type DaemonSetProber struct { + err error +} + +func NewDaemonSetProber(err error) *DaemonSetProber { + return &DaemonSetProber{ + err: err, + } +} + +func (d *DaemonSetProber) IsReady(ctx context.Context, name types.NamespacedName) error { + return d.err +} diff --git a/internal/reconciler/commonstatus/stubs/deployment_set_prober.go b/internal/reconciler/commonstatus/stubs/deployment_set_prober.go new file mode 100644 index 000000000..b36cecd83 --- /dev/null +++ b/internal/reconciler/commonstatus/stubs/deployment_set_prober.go @@ -0,0 +1,20 @@ +package stubs + +import ( + "context" + "k8s.io/apimachinery/pkg/types" +) + +type DeploymentSetProber struct { + err error +} + +func NewDeploymentSetProber(err error) *DeploymentSetProber { + return &DeploymentSetProber{ + err: err, + } +} + +func (d *DeploymentSetProber) IsReady(ctx context.Context, name types.NamespacedName) error { + return d.err +} diff --git a/internal/reconciler/logparser/mocks/daemon_set_prober.go b/internal/reconciler/logparser/mocks/daemon_set_prober.go deleted file mode 100644 index e8a367dbd..000000000 --- a/internal/reconciler/logparser/mocks/daemon_set_prober.go +++ /dev/null @@ -1,48 +0,0 @@ -// Code generated by mockery. DO NOT EDIT. - -package mocks - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" - - types "k8s.io/apimachinery/pkg/types" -) - -// DaemonSetProber is an autogenerated mock type for the DaemonSetProber type -type DaemonSetProber struct { - mock.Mock -} - -// IsReady provides a mock function with given fields: ctx, name -func (_m *DaemonSetProber) IsReady(ctx context.Context, name types.NamespacedName) error { - ret := _m.Called(ctx, name) - - if len(ret) == 0 { - panic("no return value specified for IsReady") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, types.NamespacedName) error); ok { - r0 = rf(ctx, name) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// NewDaemonSetProber creates a new instance of DaemonSetProber. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewDaemonSetProber(t interface { - mock.TestingT - Cleanup(func()) -}) *DaemonSetProber { - mock := &DaemonSetProber{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/reconciler/logparser/status_test.go b/internal/reconciler/logparser/status_test.go index 911b21f6f..12dcc13fa 100644 --- a/internal/reconciler/logparser/status_test.go +++ b/internal/reconciler/logparser/status_test.go @@ -2,9 +2,9 @@ package logparser import ( "context" + commonStatusStubs "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" "testing" - "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -15,7 +15,6 @@ import ( telemetryv1alpha1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1alpha1" "github.com/kyma-project/telemetry-manager/internal/conditions" - "github.com/kyma-project/telemetry-manager/internal/reconciler/logparser/mocks" "github.com/kyma-project/telemetry-manager/internal/workloadstatus" ) @@ -34,8 +33,7 @@ func TestUpdateStatus(t *testing.T) { } fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(parser).WithStatusSubresource(parser).Build() - proberStub := &mocks.DaemonSetProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(&workloadstatus.PodIsPendingError{ContainerName: "foo", Message: "OOMKilled"}) + proberStub := commonStatusStubs.NewDaemonSetProber(&workloadstatus.PodIsPendingError{ContainerName: "foo", Message: "OOMKilled"}) errToMsgConverter := &conditions.ErrorToMessageConverter{} @@ -74,8 +72,7 @@ func TestUpdateStatus(t *testing.T) { } fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(parser).WithStatusSubresource(parser).Build() - proberStub := &mocks.DaemonSetProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + proberStub := commonStatusStubs.NewDaemonSetProber(nil) errToMsgConverter := &conditions.ErrorToMessageConverter{} diff --git a/internal/reconciler/logpipeline/mocks/daemon_set_prober.go b/internal/reconciler/logpipeline/mocks/daemon_set_prober.go deleted file mode 100644 index e8a367dbd..000000000 --- a/internal/reconciler/logpipeline/mocks/daemon_set_prober.go +++ /dev/null @@ -1,48 +0,0 @@ -// Code generated by mockery. DO NOT EDIT. - -package mocks - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" - - types "k8s.io/apimachinery/pkg/types" -) - -// DaemonSetProber is an autogenerated mock type for the DaemonSetProber type -type DaemonSetProber struct { - mock.Mock -} - -// IsReady provides a mock function with given fields: ctx, name -func (_m *DaemonSetProber) IsReady(ctx context.Context, name types.NamespacedName) error { - ret := _m.Called(ctx, name) - - if len(ret) == 0 { - panic("no return value specified for IsReady") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, types.NamespacedName) error); ok { - r0 = rf(ctx, name) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// NewDaemonSetProber creates a new instance of DaemonSetProber. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewDaemonSetProber(t interface { - mock.TestingT - Cleanup(func()) -}) *DaemonSetProber { - mock := &DaemonSetProber{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/reconciler/logpipeline/reconciler_test.go b/internal/reconciler/logpipeline/reconciler_test.go index 25e6074e0..094824177 100644 --- a/internal/reconciler/logpipeline/reconciler_test.go +++ b/internal/reconciler/logpipeline/reconciler_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + commonStatusStubs "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" "testing" "time" @@ -65,8 +66,7 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewLogPipelineBuilder().WithFinalizer("FLUENT_BIT_SECTIONS_CONFIG_MAP").WithCustomFilter("Name grep").Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - proberStub := &logMocks.DaemonSetProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + proberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &logMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) @@ -89,8 +89,7 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewLogPipelineBuilder().WithFinalizer("FLUENT_BIT_SECTIONS_CONFIG_MAP").Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - proberStub := &logMocks.DaemonSetProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + proberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &logMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) @@ -113,8 +112,7 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewLogPipelineBuilder().WithFinalizer("FLUENT_BIT_SECTIONS_CONFIG_MAP").Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - proberStub := &logMocks.DaemonSetProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(workloadstatus.ErrDaemonSetNotFound) + proberStub := commonStatusStubs.NewDaemonSetProber(workloadstatus.ErrDaemonSetNotFound) flowHealthProberStub := &logMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) @@ -148,8 +146,7 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewLogPipelineBuilder().WithFinalizer("FLUENT_BIT_SECTIONS_CONFIG_MAP").Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - proberStub := &logMocks.DaemonSetProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + proberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &logMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) @@ -182,8 +179,7 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewLogPipelineBuilder().WithFinalizer("FLUENT_BIT_SECTIONS_CONFIG_MAP").Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - proberStub := &logMocks.DaemonSetProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(workloadstatus.ErrDaemonSetFetching) + proberStub := commonStatusStubs.NewDaemonSetProber(workloadstatus.ErrDaemonSetFetching) flowHealthProberStub := &logMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) @@ -218,8 +214,7 @@ func TestReconcile(t *testing.T) { Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - proberStub := &logMocks.DaemonSetProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + proberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &logMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) @@ -303,8 +298,7 @@ func TestReconcile(t *testing.T) { Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline, secret).WithStatusSubresource(&pipeline).Build() - proberStub := &logMocks.DaemonSetProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + proberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &logMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) @@ -338,8 +332,7 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewLogPipelineBuilder().WithFinalizer("FLUENT_BIT_SECTIONS_CONFIG_MAP").WithLokiOutput().Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - proberStub := &logMocks.DaemonSetProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + proberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &logMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) @@ -474,8 +467,7 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewLogPipelineBuilder().WithFinalizer("FLUENT_BIT_SECTIONS_CONFIG_MAP").Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - agentProberStub := &logMocks.DaemonSetProber{} - agentProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + proberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &logMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(tt.probe, tt.probeErr) @@ -485,7 +477,7 @@ func TestReconcile(t *testing.T) { errToMsgStub := &logMocks.ErrorToMessageConverter{} errToMsgStub.On("Convert", mock.Anything).Return("") - sut := New(fakeClient, testConfig, agentProberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) + sut := New(fakeClient, testConfig, proberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) _, err := sut.Reconcile(context.Background(), ctrl.Request{NamespacedName: types.NamespacedName{Name: pipeline.Name}}) require.NoError(t, err) @@ -590,8 +582,7 @@ func TestReconcile(t *testing.T) { Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - proberStub := &logMocks.DaemonSetProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + proberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &logMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) @@ -678,8 +669,7 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewLogPipelineBuilder().WithFinalizer("FLUENT_BIT_SECTIONS_CONFIG_MAP").Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - agentProberStub := &logMocks.DaemonSetProber{} - agentProberStub.On("IsReady", mock.Anything, mock.Anything).Return(tt.probeErr) + proberStub := commonStatusStubs.NewDaemonSetProber(tt.probeErr) flowHealthProberStub := &logMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) @@ -687,9 +677,8 @@ func TestReconcile(t *testing.T) { pipelineValidatorWithStubs := &Validator{TLSCertValidator: stubs.NewTLSCertValidator(nil), SecretRefValidator: stubs.NewSecretRefValidator(nil)} errToMsgStub := &conditions.ErrorToMessageConverter{} - //errToMsgStub.On("Convert", mock.Anything).Return("") - sut := New(fakeClient, testConfig, agentProberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) + sut := New(fakeClient, testConfig, proberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) _, err := sut.Reconcile(context.Background(), ctrl.Request{NamespacedName: types.NamespacedName{Name: pipeline.Name}}) require.NoError(t, err) @@ -715,8 +704,7 @@ func TestReconcile(t *testing.T) { Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - proberStub := &logMocks.DaemonSetProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + proberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &logMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) diff --git a/internal/reconciler/metricpipeline/mocks/daemon_set_prober.go b/internal/reconciler/metricpipeline/mocks/daemon_set_prober.go deleted file mode 100644 index e8a367dbd..000000000 --- a/internal/reconciler/metricpipeline/mocks/daemon_set_prober.go +++ /dev/null @@ -1,48 +0,0 @@ -// Code generated by mockery. DO NOT EDIT. - -package mocks - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" - - types "k8s.io/apimachinery/pkg/types" -) - -// DaemonSetProber is an autogenerated mock type for the DaemonSetProber type -type DaemonSetProber struct { - mock.Mock -} - -// IsReady provides a mock function with given fields: ctx, name -func (_m *DaemonSetProber) IsReady(ctx context.Context, name types.NamespacedName) error { - ret := _m.Called(ctx, name) - - if len(ret) == 0 { - panic("no return value specified for IsReady") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, types.NamespacedName) error); ok { - r0 = rf(ctx, name) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// NewDaemonSetProber creates a new instance of DaemonSetProber. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewDaemonSetProber(t interface { - mock.TestingT - Cleanup(func()) -}) *DaemonSetProber { - mock := &DaemonSetProber{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/reconciler/metricpipeline/mocks/deployment_prober.go b/internal/reconciler/metricpipeline/mocks/deployment_prober.go deleted file mode 100644 index 4ef238e39..000000000 --- a/internal/reconciler/metricpipeline/mocks/deployment_prober.go +++ /dev/null @@ -1,48 +0,0 @@ -// Code generated by mockery. DO NOT EDIT. - -package mocks - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" - - types "k8s.io/apimachinery/pkg/types" -) - -// DeploymentProber is an autogenerated mock type for the DeploymentProber type -type DeploymentProber struct { - mock.Mock -} - -// IsReady provides a mock function with given fields: ctx, name -func (_m *DeploymentProber) IsReady(ctx context.Context, name types.NamespacedName) error { - ret := _m.Called(ctx, name) - - if len(ret) == 0 { - panic("no return value specified for IsReady") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, types.NamespacedName) error); ok { - r0 = rf(ctx, name) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// NewDeploymentProber creates a new instance of DeploymentProber. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewDeploymentProber(t interface { - mock.TestingT - Cleanup(func()) -}) *DeploymentProber { - mock := &DeploymentProber{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/reconciler/metricpipeline/reconciler_test.go b/internal/reconciler/metricpipeline/reconciler_test.go index 9257b55e2..516397581 100644 --- a/internal/reconciler/metricpipeline/reconciler_test.go +++ b/internal/reconciler/metricpipeline/reconciler_test.go @@ -25,6 +25,7 @@ import ( "github.com/kyma-project/telemetry-manager/internal/otelcollector/config/metric/agent" "github.com/kyma-project/telemetry-manager/internal/otelcollector/config/metric/gateway" "github.com/kyma-project/telemetry-manager/internal/overrides" + commonStatusStubs "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" metricMocks "github.com/kyma-project/telemetry-manager/internal/reconciler/metricpipeline/mocks" "github.com/kyma-project/telemetry-manager/internal/reconciler/metricpipeline/stubs" "github.com/kyma-project/telemetry-manager/internal/resourcelock" @@ -83,8 +84,8 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(&workloadstatus.PodIsPendingError{ContainerName: "foo", Message: "Error"}) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(&workloadstatus.PodIsPendingError{ContainerName: "foo", Message: "Error"}) + agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -102,7 +103,7 @@ func TestReconcile(t *testing.T) { testConfig, &metricMocks.AgentApplierDeleter{}, &metricMocks.AgentConfigBuilder{}, - &metricMocks.DaemonSetProber{}, + agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, gatewayConfigBuilderMock, @@ -142,8 +143,8 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(workloadstatus.ErrDeploymentFetching) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(workloadstatus.ErrDeploymentFetching) + agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -161,7 +162,7 @@ func TestReconcile(t *testing.T) { testConfig, &metricMocks.AgentApplierDeleter{}, &metricMocks.AgentConfigBuilder{}, - &metricMocks.DaemonSetProber{}, + agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, gatewayConfigBuilderMock, @@ -201,8 +202,8 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) + agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -220,7 +221,7 @@ func TestReconcile(t *testing.T) { testConfig, &metricMocks.AgentApplierDeleter{}, &metricMocks.AgentConfigBuilder{}, - &metricMocks.DaemonSetProber{}, + agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, gatewayConfigBuilderMock, @@ -266,11 +267,9 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) - agentProberStub := &metricMocks.DaemonSetProber{} - agentProberStub.On("IsReady", mock.Anything, mock.Anything).Return(&workloadstatus.PodIsPendingError{Message: "Error"}) + agentProberStub := commonStatusStubs.NewDaemonSetProber(&workloadstatus.PodIsPendingError{Message: "Error"}) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -334,11 +333,9 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) - agentProberMock := &metricMocks.DaemonSetProber{} - agentProberMock.On("IsReady", mock.Anything, mock.Anything).Return(workloadstatus.ErrDaemonSetNotFound) + agentProberStub := commonStatusStubs.NewDaemonSetProber(workloadstatus.ErrDaemonSetNotFound) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -356,7 +353,7 @@ func TestReconcile(t *testing.T) { testConfig, agentApplierDeleterMock, agentConfigBuilderMock, - agentProberMock, + agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, gatewayConfigBuilderMock, @@ -403,11 +400,9 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) - agentProberMock := &metricMocks.DaemonSetProber{} - agentProberMock.On("IsReady", mock.Anything, mock.Anything).Return(nil) + agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -425,7 +420,7 @@ func TestReconcile(t *testing.T) { testConfig, agentApplierDeleterMock, agentConfigBuilderMock, - agentProberMock, + agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, gatewayConfigBuilderMock, @@ -474,8 +469,8 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) + agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -493,7 +488,7 @@ func TestReconcile(t *testing.T) { testConfig, &metricMocks.AgentApplierDeleter{}, &metricMocks.AgentConfigBuilder{}, - &metricMocks.DaemonSetProber{}, + agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, gatewayConfigBuilderMock, @@ -536,8 +531,8 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) + agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -555,7 +550,7 @@ func TestReconcile(t *testing.T) { testConfig, agentApplierDeleterMock, &metricMocks.AgentConfigBuilder{}, - &metricMocks.DaemonSetProber{}, + agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, gatewayConfigBuilderMock, @@ -599,8 +594,9 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(resourcelock.ErrMaxPipelinesExceeded) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(resourcelock.ErrMaxPipelinesExceeded) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) + + agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -617,7 +613,7 @@ func TestReconcile(t *testing.T) { testConfig, &metricMocks.AgentApplierDeleter{}, &metricMocks.AgentConfigBuilder{}, - &metricMocks.DaemonSetProber{}, + agentProberStub, flowHealthProberStub, &metricMocks.GatewayApplierDeleter{}, gatewayConfigBuilderMock, @@ -759,8 +755,9 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) + + agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(tt.probe, tt.probeErr) @@ -777,7 +774,7 @@ func TestReconcile(t *testing.T) { testConfig, &metricMocks.AgentApplierDeleter{}, &metricMocks.AgentConfigBuilder{}, - &metricMocks.DaemonSetProber{}, + agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, gatewayConfigBuilderMock, @@ -901,8 +898,8 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) + agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -920,7 +917,7 @@ func TestReconcile(t *testing.T) { testConfig, agentApplierDeleterMock, &metricMocks.AgentConfigBuilder{}, - &metricMocks.DaemonSetProber{}, + agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, gatewayConfigBuilderMock, @@ -985,8 +982,8 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) + agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -1005,7 +1002,7 @@ func TestReconcile(t *testing.T) { testConfig, &metricMocks.AgentApplierDeleter{}, &metricMocks.AgentConfigBuilder{}, - &metricMocks.DaemonSetProber{}, + agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, gatewayConfigBuilderMock, @@ -1054,8 +1051,8 @@ func TestReconcile(t *testing.T) { serverErr := errors.New("failed to get lock: server error") pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(&errortypes.APIRequestFailedError{Err: serverErr}) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) + agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -1073,7 +1070,7 @@ func TestReconcile(t *testing.T) { testConfig, &metricMocks.AgentApplierDeleter{}, &metricMocks.AgentConfigBuilder{}, - &metricMocks.DaemonSetProber{}, + agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, gatewayConfigBuilderMock, @@ -1127,11 +1124,8 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) - - agentProberStub := &metricMocks.DaemonSetProber{} - agentProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) + agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -1250,11 +1244,8 @@ func TestReconcile(t *testing.T) { gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &metricMocks.DeploymentProber{} - agentProberMock := &metricMocks.DaemonSetProber{} - - agentProberMock.On("IsReady", mock.Anything, mock.Anything).Return(tt.probeAgentErr) - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(tt.probeGatewayErr) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(tt.probeGatewayErr) + agentProberMock := commonStatusStubs.NewDaemonSetProber(tt.probeAgentErr) flowHealthProberStub := &metricMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) diff --git a/internal/reconciler/tracepipeline/mocks/deployment_prober.go b/internal/reconciler/tracepipeline/mocks/deployment_prober.go deleted file mode 100644 index 4ef238e39..000000000 --- a/internal/reconciler/tracepipeline/mocks/deployment_prober.go +++ /dev/null @@ -1,48 +0,0 @@ -// Code generated by mockery. DO NOT EDIT. - -package mocks - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" - - types "k8s.io/apimachinery/pkg/types" -) - -// DeploymentProber is an autogenerated mock type for the DeploymentProber type -type DeploymentProber struct { - mock.Mock -} - -// IsReady provides a mock function with given fields: ctx, name -func (_m *DeploymentProber) IsReady(ctx context.Context, name types.NamespacedName) error { - ret := _m.Called(ctx, name) - - if len(ret) == 0 { - panic("no return value specified for IsReady") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, types.NamespacedName) error); ok { - r0 = rf(ctx, name) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// NewDeploymentProber creates a new instance of DeploymentProber. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewDeploymentProber(t interface { - mock.TestingT - Cleanup(func()) -}) *DeploymentProber { - mock := &DeploymentProber{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/reconciler/tracepipeline/reconciler_test.go b/internal/reconciler/tracepipeline/reconciler_test.go index 3ac0a0827..622ff69eb 100644 --- a/internal/reconciler/tracepipeline/reconciler_test.go +++ b/internal/reconciler/tracepipeline/reconciler_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + commonStatusStubs "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" "testing" "time" @@ -71,8 +72,7 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &traceMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(workloadstatus.ErrDeploymentFetching) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(workloadstatus.ErrDeploymentFetching) flowHealthProberStub := &traceMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -128,9 +128,7 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &traceMocks.DeploymentProber{} - cnre := &workloadstatus.PodIsPendingError{ContainerName: "foo", Message: "Error"} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(cnre) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(&workloadstatus.PodIsPendingError{ContainerName: "foo", Message: "Error"}) flowHealthProberStub := &traceMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -186,8 +184,7 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &traceMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) flowHealthProberStub := &traceMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -242,8 +239,7 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - proberStub := &traceMocks.DeploymentProber{} - proberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) flowHealthProberStub := &traceMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -262,7 +258,7 @@ func TestReconcile(t *testing.T) { flowHealthProberStub, gatewayApplierDeleterMock, gatewayConfigBuilderMock, - proberStub, + gatewayProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineLockStub, @@ -316,8 +312,7 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &traceMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) flowHealthProberStub := &traceMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -369,8 +364,7 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(resourcelock.ErrMaxPipelinesExceeded) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(resourcelock.ErrMaxPipelinesExceeded) - gatewayProberStub := &traceMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) flowHealthProberStub := &traceMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -526,8 +520,7 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &traceMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) flowHealthProberStub := &traceMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(tt.probe, tt.probeErr) @@ -661,8 +654,7 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(true, nil) - gatewayProberStub := &traceMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) flowHealthProberStub := &traceMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -743,8 +735,7 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &traceMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) flowHealthProberStub := &traceMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -808,8 +799,7 @@ func TestReconcile(t *testing.T) { serverErr := errors.New("failed to get lock: server error") pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(&errortypes.APIRequestFailedError{Err: serverErr}) - gatewayProberStub := &traceMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) flowHealthProberStub := &traceMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -871,8 +861,7 @@ func TestReconcile(t *testing.T) { pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) - gatewayProberStub := &traceMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(nil) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) flowHealthProberStub := &traceMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) @@ -968,8 +957,7 @@ func TestReconcile(t *testing.T) { PipelineLock: pipelineLockStub, } - gatewayProberStub := &traceMocks.DeploymentProber{} - gatewayProberStub.On("IsReady", mock.Anything, mock.Anything).Return(tt.probeGatewayErr) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(tt.probeGatewayErr) flowHealthProberStub := &traceMocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) From f5c390f99647cb2411d88529c1e5f38d980f20cb Mon Sep 17 00:00:00 2001 From: Rakesh Garimella Date: Tue, 6 Aug 2024 10:12:51 +0200 Subject: [PATCH 2/2] lint fix --- .golangci.yaml | 8 +- .../reconciler/commonstatus/checker_test.go | 10 +- .../commonstatus/stubs/daemon_set_prober.go | 1 + .../stubs/deployment_set_prober.go | 1 + internal/reconciler/logparser/status_test.go | 2 +- .../reconciler/logpipeline/reconciler_test.go | 52 ++--- .../metricpipeline/reconciler_test.go | 186 +++++++++--------- .../tracepipeline/reconciler_test.go | 104 +++++----- 8 files changed, 181 insertions(+), 183 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 481f8fa37..8d6308da2 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -121,12 +121,8 @@ linters-settings: alias: metricsserver - pkg: sigs.k8s.io/controller-runtime/pkg/predicate alias: ctrlpredicate - - pkg: "github.com/kyma-project/telemetry-manager/internal/reconciler/logpipeline/mocks" - alias: logMocks - - pkg: "github.com/kyma-project/telemetry-manager/internal/reconciler/metricpipeline/mocks" - alias: metricMocks - - pkg: "github.com/kyma-project/telemetry-manager/internal/reconciler/tracepipeline/mocks" - alias: traceMocks + - pkg: "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" + alias: commonStatusStubs errcheck: check-type-assertions: true # Reports type assertions: `a := b.(SomeStruct)`. check-blank: true # Report assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`. diff --git a/internal/reconciler/commonstatus/checker_test.go b/internal/reconciler/commonstatus/checker_test.go index 1e9866201..fe8b98ef7 100644 --- a/internal/reconciler/commonstatus/checker_test.go +++ b/internal/reconciler/commonstatus/checker_test.go @@ -3,7 +3,6 @@ package commonstatus import ( "context" "fmt" - "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" "testing" "github.com/stretchr/testify/require" @@ -11,6 +10,7 @@ import ( "k8s.io/apimachinery/pkg/types" "github.com/kyma-project/telemetry-manager/internal/conditions" + commonStatusStubs "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" "github.com/kyma-project/telemetry-manager/internal/workloadstatus" ) @@ -63,7 +63,7 @@ func TestTracesGetHealthCondition(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gatewayProberStub := stubs.NewDeploymentSetProber(tt.proberErr) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(tt.proberErr) actualCondition := GetGatewayHealthyCondition(context.TODO(), gatewayProberStub, types.NamespacedName{}, &conditions.ErrorToMessageConverter{}, SignalTypeTraces) require.True(t, validateCondition(t, tt.expectedCondition, actualCondition)) }) @@ -150,8 +150,8 @@ func TestMetricsGetHealthCondition(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - agentProberStub := stubs.NewDaemonSetProber(tt.proberAgentErr) - gatewayProberStub := stubs.NewDeploymentSetProber(tt.preberGatewayErr) + agentProberStub := commonStatusStubs.NewDaemonSetProber(tt.proberAgentErr) + gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(tt.preberGatewayErr) actualAgentCondition := GetAgentHealthyCondition(context.TODO(), agentProberStub, types.NamespacedName{}, &conditions.ErrorToMessageConverter{}, SignalTypeMetrics) actualGatewayCondition := GetGatewayHealthyCondition(context.TODO(), gatewayProberStub, types.NamespacedName{}, &conditions.ErrorToMessageConverter{}, SignalTypeMetrics) @@ -211,7 +211,7 @@ func TestLogsGetHealthCondition(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - agentProberStub := stubs.NewDaemonSetProber(tt.proberErr) + agentProberStub := commonStatusStubs.NewDaemonSetProber(tt.proberErr) actualCondition := GetAgentHealthyCondition(context.TODO(), agentProberStub, types.NamespacedName{}, &conditions.ErrorToMessageConverter{}, SignalTypeLogs) require.True(t, validateCondition(t, tt.expectedCondition, actualCondition)) }) diff --git a/internal/reconciler/commonstatus/stubs/daemon_set_prober.go b/internal/reconciler/commonstatus/stubs/daemon_set_prober.go index 010cdf1b5..0cfee17f2 100644 --- a/internal/reconciler/commonstatus/stubs/daemon_set_prober.go +++ b/internal/reconciler/commonstatus/stubs/daemon_set_prober.go @@ -2,6 +2,7 @@ package stubs import ( "context" + "k8s.io/apimachinery/pkg/types" ) diff --git a/internal/reconciler/commonstatus/stubs/deployment_set_prober.go b/internal/reconciler/commonstatus/stubs/deployment_set_prober.go index b36cecd83..f92729349 100644 --- a/internal/reconciler/commonstatus/stubs/deployment_set_prober.go +++ b/internal/reconciler/commonstatus/stubs/deployment_set_prober.go @@ -2,6 +2,7 @@ package stubs import ( "context" + "k8s.io/apimachinery/pkg/types" ) diff --git a/internal/reconciler/logparser/status_test.go b/internal/reconciler/logparser/status_test.go index 12dcc13fa..629749c23 100644 --- a/internal/reconciler/logparser/status_test.go +++ b/internal/reconciler/logparser/status_test.go @@ -2,7 +2,6 @@ package logparser import ( "context" - commonStatusStubs "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" "testing" "github.com/stretchr/testify/require" @@ -15,6 +14,7 @@ import ( telemetryv1alpha1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1alpha1" "github.com/kyma-project/telemetry-manager/internal/conditions" + commonStatusStubs "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" "github.com/kyma-project/telemetry-manager/internal/workloadstatus" ) diff --git a/internal/reconciler/logpipeline/reconciler_test.go b/internal/reconciler/logpipeline/reconciler_test.go index 094824177..e2abd4af7 100644 --- a/internal/reconciler/logpipeline/reconciler_test.go +++ b/internal/reconciler/logpipeline/reconciler_test.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - commonStatusStubs "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" "testing" "time" @@ -27,7 +26,8 @@ import ( "github.com/kyma-project/telemetry-manager/internal/conditions" "github.com/kyma-project/telemetry-manager/internal/errortypes" "github.com/kyma-project/telemetry-manager/internal/overrides" - logMocks "github.com/kyma-project/telemetry-manager/internal/reconciler/logpipeline/mocks" + commonStatusStubs "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" + "github.com/kyma-project/telemetry-manager/internal/reconciler/logpipeline/mocks" "github.com/kyma-project/telemetry-manager/internal/reconciler/logpipeline/stubs" "github.com/kyma-project/telemetry-manager/internal/resources/fluentbit" "github.com/kyma-project/telemetry-manager/internal/secretref" @@ -42,10 +42,10 @@ func TestReconcile(t *testing.T) { _ = clientgoscheme.AddToScheme(scheme) _ = telemetryv1alpha1.AddToScheme(scheme) - overridesHandlerStub := &logMocks.OverridesHandler{} + overridesHandlerStub := &mocks.OverridesHandler{} overridesHandlerStub.On("LoadOverrides", context.Background()).Return(&overrides.Config{}, nil) - istioStatusCheckerStub := &logMocks.IstioStatusChecker{} + istioStatusCheckerStub := &mocks.IstioStatusChecker{} istioStatusCheckerStub.On("IsIstioActive", mock.Anything).Return(false) testConfig := Config{ @@ -68,12 +68,12 @@ func TestReconcile(t *testing.T) { proberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &logMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{TLSCertValidator: stubs.NewTLSCertValidator(nil), SecretRefValidator: stubs.NewSecretRefValidator(nil)} - errToMsgStub := &logMocks.ErrorToMessageConverter{} + errToMsgStub := &mocks.ErrorToMessageConverter{} sut := New(fakeClient, testConfig, proberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) _, err := sut.Reconcile(context.Background(), ctrl.Request{NamespacedName: types.NamespacedName{Name: pipeline.Name}}) @@ -91,12 +91,12 @@ func TestReconcile(t *testing.T) { proberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &logMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{TLSCertValidator: stubs.NewTLSCertValidator(nil), SecretRefValidator: stubs.NewSecretRefValidator(nil)} - errToMsgStub := &logMocks.ErrorToMessageConverter{} + errToMsgStub := &mocks.ErrorToMessageConverter{} sut := New(fakeClient, testConfig, proberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) _, err := sut.Reconcile(context.Background(), ctrl.Request{NamespacedName: types.NamespacedName{Name: pipeline.Name}}) @@ -114,12 +114,12 @@ func TestReconcile(t *testing.T) { proberStub := commonStatusStubs.NewDaemonSetProber(workloadstatus.ErrDaemonSetNotFound) - flowHealthProberStub := &logMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{TLSCertValidator: stubs.NewTLSCertValidator(nil), SecretRefValidator: stubs.NewSecretRefValidator(nil)} - errToMsgStub := &logMocks.ErrorToMessageConverter{} + errToMsgStub := &mocks.ErrorToMessageConverter{} errToMsgStub.On("Convert", mock.Anything).Return("DaemonSet is not yet created") sut := New(fakeClient, testConfig, proberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) @@ -148,12 +148,12 @@ func TestReconcile(t *testing.T) { proberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &logMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{TLSCertValidator: stubs.NewTLSCertValidator(nil), SecretRefValidator: stubs.NewSecretRefValidator(nil)} - errToMsgStub := &logMocks.ErrorToMessageConverter{} + errToMsgStub := &mocks.ErrorToMessageConverter{} sut := New(fakeClient, testConfig, proberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) _, err := sut.Reconcile(context.Background(), ctrl.Request{NamespacedName: types.NamespacedName{Name: pipeline.Name}}) @@ -181,7 +181,7 @@ func TestReconcile(t *testing.T) { proberStub := commonStatusStubs.NewDaemonSetProber(workloadstatus.ErrDaemonSetFetching) - flowHealthProberStub := &logMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{TLSCertValidator: stubs.NewTLSCertValidator(nil), SecretRefValidator: stubs.NewSecretRefValidator(nil)} @@ -216,7 +216,7 @@ func TestReconcile(t *testing.T) { proberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &logMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -224,7 +224,7 @@ func TestReconcile(t *testing.T) { SecretRefValidator: stubs.NewSecretRefValidator(fmt.Errorf("%w: Secret 'some-secret' of Namespace 'some-namespace'", secretref.ErrSecretRefNotFound)), } - errToMsgStub := &logMocks.ErrorToMessageConverter{} + errToMsgStub := &mocks.ErrorToMessageConverter{} errToMsgStub.On("Convert", mock.Anything).Return("") sut := New(fakeClient, testConfig, proberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) @@ -300,12 +300,12 @@ func TestReconcile(t *testing.T) { proberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &logMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{TLSCertValidator: stubs.NewTLSCertValidator(nil), SecretRefValidator: stubs.NewSecretRefValidator(nil)} - errToMsgStub := &logMocks.ErrorToMessageConverter{} + errToMsgStub := &mocks.ErrorToMessageConverter{} errToMsgStub.On("Convert", mock.Anything).Return("") sut := New(fakeClient, testConfig, proberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) @@ -334,12 +334,12 @@ func TestReconcile(t *testing.T) { proberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &logMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{TLSCertValidator: stubs.NewTLSCertValidator(nil), SecretRefValidator: stubs.NewSecretRefValidator(nil)} - errToMsgStub := &logMocks.ErrorToMessageConverter{} + errToMsgStub := &mocks.ErrorToMessageConverter{} sut := New(fakeClient, testConfig, proberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) _, err := sut.Reconcile(context.Background(), ctrl.Request{NamespacedName: types.NamespacedName{Name: pipeline.Name}}) @@ -469,12 +469,12 @@ func TestReconcile(t *testing.T) { proberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &logMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(tt.probe, tt.probeErr) pipelineValidatorWithStubs := &Validator{TLSCertValidator: stubs.NewTLSCertValidator(nil), SecretRefValidator: stubs.NewSecretRefValidator(nil)} - errToMsgStub := &logMocks.ErrorToMessageConverter{} + errToMsgStub := &mocks.ErrorToMessageConverter{} errToMsgStub.On("Convert", mock.Anything).Return("") sut := New(fakeClient, testConfig, proberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) @@ -584,12 +584,12 @@ func TestReconcile(t *testing.T) { proberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &logMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{TLSCertValidator: stubs.NewTLSCertValidator(nil), SecretRefValidator: stubs.NewSecretRefValidator(tt.tlsCertErr)} - errToMsgStub := &logMocks.ErrorToMessageConverter{} + errToMsgStub := &mocks.ErrorToMessageConverter{} errToMsgStub.On("Convert", mock.Anything).Return("") sut := New(fakeClient, testConfig, proberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) @@ -671,7 +671,7 @@ func TestReconcile(t *testing.T) { proberStub := commonStatusStubs.NewDaemonSetProber(tt.probeErr) - flowHealthProberStub := &logMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{TLSCertValidator: stubs.NewTLSCertValidator(nil), SecretRefValidator: stubs.NewSecretRefValidator(nil)} @@ -706,7 +706,7 @@ func TestReconcile(t *testing.T) { proberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &logMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.LogPipelineProbeResult{}, nil) serverErr := errors.New("failed to get secret: server error") @@ -715,7 +715,7 @@ func TestReconcile(t *testing.T) { SecretRefValidator: stubs.NewSecretRefValidator(&errortypes.APIRequestFailedError{Err: serverErr}), } - errToMsgStub := &logMocks.ErrorToMessageConverter{} + errToMsgStub := &mocks.ErrorToMessageConverter{} sut := New(fakeClient, testConfig, proberStub, flowHealthProberStub, istioStatusCheckerStub, overridesHandlerStub, pipelineValidatorWithStubs, errToMsgStub) _, err := sut.Reconcile(context.Background(), ctrl.Request{NamespacedName: types.NamespacedName{Name: pipeline.Name}}) diff --git a/internal/reconciler/metricpipeline/reconciler_test.go b/internal/reconciler/metricpipeline/reconciler_test.go index 516397581..125cbc109 100644 --- a/internal/reconciler/metricpipeline/reconciler_test.go +++ b/internal/reconciler/metricpipeline/reconciler_test.go @@ -26,7 +26,7 @@ import ( "github.com/kyma-project/telemetry-manager/internal/otelcollector/config/metric/gateway" "github.com/kyma-project/telemetry-manager/internal/overrides" commonStatusStubs "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" - metricMocks "github.com/kyma-project/telemetry-manager/internal/reconciler/metricpipeline/mocks" + "github.com/kyma-project/telemetry-manager/internal/reconciler/metricpipeline/mocks" "github.com/kyma-project/telemetry-manager/internal/reconciler/metricpipeline/stubs" "github.com/kyma-project/telemetry-manager/internal/resourcelock" "github.com/kyma-project/telemetry-manager/internal/resources/otelcollector" @@ -42,10 +42,10 @@ func TestReconcile(t *testing.T) { _ = clientgoscheme.AddToScheme(scheme) _ = telemetryv1alpha1.AddToScheme(scheme) - overridesHandlerStub := &metricMocks.OverridesHandler{} + overridesHandlerStub := &mocks.OverridesHandler{} overridesHandlerStub.On("LoadOverrides", context.Background()).Return(&overrides.Config{}, nil) - istioStatusCheckerStub := &metricMocks.IstioStatusChecker{} + istioStatusCheckerStub := &mocks.IstioStatusChecker{} istioStatusCheckerStub.On("IsIstioActive", mock.Anything).Return(false) testConfig := Config{ @@ -74,20 +74,20 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(&workloadstatus.PodIsPendingError{ContainerName: "foo", Message: "Error"}) agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -101,8 +101,8 @@ func TestReconcile(t *testing.T) { sut := New( fakeClient, testConfig, - &metricMocks.AgentApplierDeleter{}, - &metricMocks.AgentConfigBuilder{}, + &mocks.AgentApplierDeleter{}, + &mocks.AgentConfigBuilder{}, agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, @@ -133,20 +133,20 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(workloadstatus.ErrDeploymentFetching) agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) errToMsg := &conditions.ErrorToMessageConverter{} @@ -160,8 +160,8 @@ func TestReconcile(t *testing.T) { sut := New( fakeClient, testConfig, - &metricMocks.AgentApplierDeleter{}, - &metricMocks.AgentConfigBuilder{}, + &mocks.AgentApplierDeleter{}, + &mocks.AgentConfigBuilder{}, agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, @@ -192,20 +192,20 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -219,8 +219,8 @@ func TestReconcile(t *testing.T) { sut := New( fakeClient, testConfig, - &metricMocks.AgentApplierDeleter{}, - &metricMocks.AgentConfigBuilder{}, + &mocks.AgentApplierDeleter{}, + &mocks.AgentConfigBuilder{}, agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, @@ -251,19 +251,19 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().WithPrometheusInput(true).Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - agentConfigBuilderMock := &metricMocks.AgentConfigBuilder{} + agentConfigBuilderMock := &mocks.AgentConfigBuilder{} agentConfigBuilderMock.On("Build", containsPipeline(pipeline), mock.Anything).Return(&agent.Config{}).Times(1) - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - agentApplierDeleterMock := &metricMocks.AgentApplierDeleter{} + agentApplierDeleterMock := &mocks.AgentApplierDeleter{} agentApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) @@ -271,7 +271,7 @@ func TestReconcile(t *testing.T) { agentProberStub := commonStatusStubs.NewDaemonSetProber(&workloadstatus.PodIsPendingError{Message: "Error"}) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -317,19 +317,19 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().WithPrometheusInput(true).Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - agentConfigBuilderMock := &metricMocks.AgentConfigBuilder{} + agentConfigBuilderMock := &mocks.AgentConfigBuilder{} agentConfigBuilderMock.On("Build", containsPipeline(pipeline), mock.Anything).Return(&agent.Config{}).Times(1) - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - agentApplierDeleterMock := &metricMocks.AgentApplierDeleter{} + agentApplierDeleterMock := &mocks.AgentApplierDeleter{} agentApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) @@ -337,7 +337,7 @@ func TestReconcile(t *testing.T) { agentProberStub := commonStatusStubs.NewDaemonSetProber(workloadstatus.ErrDaemonSetNotFound) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -384,19 +384,19 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().WithPrometheusInput(true).Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - agentConfigBuilderMock := &metricMocks.AgentConfigBuilder{} + agentConfigBuilderMock := &mocks.AgentConfigBuilder{} agentConfigBuilderMock.On("Build", containsPipeline(pipeline), mock.Anything).Return(&agent.Config{}).Times(1) - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - agentApplierDeleterMock := &metricMocks.AgentApplierDeleter{} + agentApplierDeleterMock := &mocks.AgentApplierDeleter{} agentApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) @@ -404,7 +404,7 @@ func TestReconcile(t *testing.T) { agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -459,20 +459,20 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().WithOTLPOutput(testutils.OTLPBasicAuthFromSecret(secret.Name, secret.Namespace, "user", "password")).Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline, secret).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -486,8 +486,8 @@ func TestReconcile(t *testing.T) { sut := New( fakeClient, testConfig, - &metricMocks.AgentApplierDeleter{}, - &metricMocks.AgentConfigBuilder{}, + &mocks.AgentApplierDeleter{}, + &mocks.AgentConfigBuilder{}, agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, @@ -518,23 +518,23 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().WithOTLPOutput(testutils.OTLPBasicAuthFromSecret("some-secret", "some-namespace", "user", "password")).Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil) - agentApplierDeleterMock := &metricMocks.AgentApplierDeleter{} + agentApplierDeleterMock := &mocks.AgentApplierDeleter{} agentApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything).Return(nil) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -549,7 +549,7 @@ func TestReconcile(t *testing.T) { fakeClient, testConfig, agentApplierDeleterMock, - &metricMocks.AgentConfigBuilder{}, + &mocks.AgentConfigBuilder{}, agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, @@ -587,10 +587,10 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(resourcelock.ErrMaxPipelinesExceeded) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(resourcelock.ErrMaxPipelinesExceeded) @@ -598,7 +598,7 @@ func TestReconcile(t *testing.T) { agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -611,11 +611,11 @@ func TestReconcile(t *testing.T) { sut := New( fakeClient, testConfig, - &metricMocks.AgentApplierDeleter{}, - &metricMocks.AgentConfigBuilder{}, + &mocks.AgentApplierDeleter{}, + &mocks.AgentConfigBuilder{}, agentProberStub, flowHealthProberStub, - &metricMocks.GatewayApplierDeleter{}, + &mocks.GatewayApplierDeleter{}, gatewayConfigBuilderMock, gatewayProberStub, istioStatusCheckerStub, @@ -745,13 +745,13 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) @@ -759,7 +759,7 @@ func TestReconcile(t *testing.T) { agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(tt.probe, tt.probeErr) pipelineValidatorWithStubs := &Validator{ @@ -772,8 +772,8 @@ func TestReconcile(t *testing.T) { sut := New( fakeClient, testConfig, - &metricMocks.AgentApplierDeleter{}, - &metricMocks.AgentConfigBuilder{}, + &mocks.AgentApplierDeleter{}, + &mocks.AgentConfigBuilder{}, agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, @@ -883,25 +883,25 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().WithOTLPOutput(testutils.OTLPClientTLSFromString("ca", "fooCert", "fooKey")).Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - agentApplierDeleterMock := &metricMocks.AgentApplierDeleter{} + agentApplierDeleterMock := &mocks.AgentApplierDeleter{} agentApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) agentApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything).Return(nil) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) gatewayApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -916,7 +916,7 @@ func TestReconcile(t *testing.T) { fakeClient, testConfig, agentApplierDeleterMock, - &metricMocks.AgentConfigBuilder{}, + &mocks.AgentConfigBuilder{}, agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, @@ -972,20 +972,20 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().WithOTLPOutput(testutils.OTLPBasicAuthFromSecret(secret.Name, secret.Namespace, "user", "password")).Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline, secret).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, mock.Anything).Return(&gateway.Config{}, nil, nil) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) serverErr := errors.New("failed to get secret: server error") @@ -1000,8 +1000,8 @@ func TestReconcile(t *testing.T) { sut := New( fakeClient, testConfig, - &metricMocks.AgentApplierDeleter{}, - &metricMocks.AgentConfigBuilder{}, + &mocks.AgentApplierDeleter{}, + &mocks.AgentConfigBuilder{}, agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, @@ -1040,13 +1040,13 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().WithName("pipeline").Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, mock.Anything).Return(&gateway.Config{}, nil, nil) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) serverErr := errors.New("failed to get lock: server error") pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(&errortypes.APIRequestFailedError{Err: serverErr}) @@ -1054,7 +1054,7 @@ func TestReconcile(t *testing.T) { gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -1068,8 +1068,8 @@ func TestReconcile(t *testing.T) { sut := New( fakeClient, testConfig, - &metricMocks.AgentApplierDeleter{}, - &metricMocks.AgentConfigBuilder{}, + &mocks.AgentApplierDeleter{}, + &mocks.AgentConfigBuilder{}, agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, @@ -1111,23 +1111,23 @@ func TestReconcile(t *testing.T) { Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil) - agentApplierDeleterMock := &metricMocks.AgentApplierDeleter{} + agentApplierDeleterMock := &mocks.AgentApplierDeleter{} agentApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything).Return(nil).Times(1) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything, mock.Anything).Return(nil).Times(1) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) agentProberStub := commonStatusStubs.NewDaemonSetProber(nil) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -1142,7 +1142,7 @@ func TestReconcile(t *testing.T) { fakeClient, testConfig, agentApplierDeleterMock, - &metricMocks.AgentConfigBuilder{}, + &mocks.AgentConfigBuilder{}, agentProberStub, flowHealthProberStub, gatewayApplierDeleterMock, @@ -1232,25 +1232,25 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewMetricPipelineBuilder().WithPrometheusInput(true).Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - agentConfigBuilderMock := &metricMocks.AgentConfigBuilder{} + agentConfigBuilderMock := &mocks.AgentConfigBuilder{} agentConfigBuilderMock.On("Build", containsPipeline(pipeline), mock.Anything).Return(&agent.Config{}).Times(1) - gatewayConfigBuilderMock := &metricMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - agentApplierDeleterMock := &metricMocks.AgentApplierDeleter{} + agentApplierDeleterMock := &mocks.AgentApplierDeleter{} agentApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - gatewayApplierDeleterMock := &metricMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(tt.probeGatewayErr) agentProberMock := commonStatusStubs.NewDaemonSetProber(tt.probeAgentErr) - flowHealthProberStub := &metricMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) - pipelineLockStub := &metricMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) diff --git a/internal/reconciler/tracepipeline/reconciler_test.go b/internal/reconciler/tracepipeline/reconciler_test.go index 622ff69eb..64f878633 100644 --- a/internal/reconciler/tracepipeline/reconciler_test.go +++ b/internal/reconciler/tracepipeline/reconciler_test.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - commonStatusStubs "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" "testing" "time" @@ -25,7 +24,8 @@ import ( "github.com/kyma-project/telemetry-manager/internal/errortypes" "github.com/kyma-project/telemetry-manager/internal/otelcollector/config/trace/gateway" "github.com/kyma-project/telemetry-manager/internal/overrides" - traceMocks "github.com/kyma-project/telemetry-manager/internal/reconciler/tracepipeline/mocks" + commonStatusStubs "github.com/kyma-project/telemetry-manager/internal/reconciler/commonstatus/stubs" + "github.com/kyma-project/telemetry-manager/internal/reconciler/tracepipeline/mocks" "github.com/kyma-project/telemetry-manager/internal/reconciler/tracepipeline/stubs" "github.com/kyma-project/telemetry-manager/internal/resourcelock" "github.com/kyma-project/telemetry-manager/internal/resources/otelcollector" @@ -41,10 +41,10 @@ func TestReconcile(t *testing.T) { _ = clientgoscheme.AddToScheme(scheme) _ = telemetryv1alpha1.AddToScheme(scheme) - overridesHandlerStub := &traceMocks.OverridesHandler{} + overridesHandlerStub := &mocks.OverridesHandler{} overridesHandlerStub.On("LoadOverrides", context.Background()).Return(&overrides.Config{}, nil) - istioStatusCheckerStub := &traceMocks.IstioStatusChecker{} + istioStatusCheckerStub := &mocks.IstioStatusChecker{} istioStatusCheckerStub.On("IsIstioActive", mock.Anything).Return(false) testConfig := Config{Gateway: otelcollector.GatewayConfig{ @@ -62,19 +62,19 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewTracePipelineBuilder().WithName("pipeline").Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &traceMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - gatewayApplierDeleterMock := &traceMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &traceMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(workloadstatus.ErrDeploymentFetching) - flowHealthProberStub := &traceMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -118,19 +118,19 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewTracePipelineBuilder().WithName("pipeline").Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &traceMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - gatewayApplierDeleterMock := &traceMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &traceMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(&workloadstatus.PodIsPendingError{ContainerName: "foo", Message: "Error"}) - flowHealthProberStub := &traceMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -174,19 +174,19 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewTracePipelineBuilder().WithName("pipeline").Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &traceMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - gatewayApplierDeleterMock := &traceMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &traceMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) - flowHealthProberStub := &traceMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -229,19 +229,19 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewTracePipelineBuilder().WithOTLPOutput(testutils.OTLPBasicAuthFromSecret("some-secret", "some-namespace", "user", "password")).Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &traceMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, mock.Anything).Return(&gateway.Config{}, nil, nil) - gatewayApplierDeleterMock := &traceMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &traceMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) - flowHealthProberStub := &traceMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -302,19 +302,19 @@ func TestReconcile(t *testing.T) { } fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline, secret).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &traceMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - gatewayApplierDeleterMock := &traceMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &traceMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) - flowHealthProberStub := &traceMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -357,16 +357,16 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewTracePipelineBuilder().Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &traceMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, mock.Anything).Return(&gateway.Config{}, nil, nil) - pipelineLockStub := &traceMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(resourcelock.ErrMaxPipelinesExceeded) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(resourcelock.ErrMaxPipelinesExceeded) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) - flowHealthProberStub := &traceMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -381,7 +381,7 @@ func TestReconcile(t *testing.T) { fakeClient, testConfig, flowHealthProberStub, - &traceMocks.GatewayApplierDeleter{}, + &mocks.GatewayApplierDeleter{}, gatewayConfigBuilderMock, gatewayProberStub, istioStatusCheckerStub, @@ -510,19 +510,19 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewTracePipelineBuilder().Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &traceMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - gatewayApplierDeleterMock := &traceMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &traceMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) - flowHealthProberStub := &traceMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(tt.probe, tt.probeErr) pipelineValidatorWithStubs := &Validator{ @@ -643,20 +643,20 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewTracePipelineBuilder().WithOTLPOutput(testutils.OTLPClientTLSFromString("ca", "fooCert", "fooKey")).Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &traceMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, mock.Anything).Return(&gateway.Config{}, nil, nil) - gatewayApplierDeleterMock := &traceMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("ApplyResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) gatewayApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &traceMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(true, nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) - flowHealthProberStub := &traceMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -725,19 +725,19 @@ func TestReconcile(t *testing.T) { } fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline, secret).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &traceMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, mock.Anything).Return(&gateway.Config{}, nil, nil) - gatewayApplierDeleterMock := &traceMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &traceMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) - flowHealthProberStub := &traceMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) serverErr := errors.New("failed to get lock: server error") @@ -788,20 +788,20 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewTracePipelineBuilder().WithName("pipeline").Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &traceMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, mock.Anything).Return(&gateway.Config{}, nil, nil) - gatewayApplierDeleterMock := &traceMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &traceMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) serverErr := errors.New("failed to get lock: server error") pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(&errortypes.APIRequestFailedError{Err: serverErr}) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) - flowHealthProberStub := &traceMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -851,19 +851,19 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewTracePipelineBuilder().WithOTLPOutput(testutils.OTLPBasicAuthFromSecret("some-secret", "some-namespace", "user", "password")).Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &traceMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, mock.Anything).Return(&gateway.Config{}, nil, nil) - gatewayApplierDeleterMock := &traceMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything, mock.Anything).Return(nil).Times(1) - pipelineLockStub := &traceMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(nil) - flowHealthProberStub := &traceMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) pipelineValidatorWithStubs := &Validator{ @@ -941,13 +941,13 @@ func TestReconcile(t *testing.T) { pipeline := testutils.NewTracePipelineBuilder().Build() fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build() - gatewayConfigBuilderMock := &traceMocks.GatewayConfigBuilder{} + gatewayConfigBuilderMock := &mocks.GatewayConfigBuilder{} gatewayConfigBuilderMock.On("Build", mock.Anything, containsPipeline(pipeline)).Return(&gateway.Config{}, nil, nil).Times(1) - gatewayApplierDeleterMock := &traceMocks.GatewayApplierDeleter{} + gatewayApplierDeleterMock := &mocks.GatewayApplierDeleter{} gatewayApplierDeleterMock.On("DeleteResources", mock.Anything, mock.Anything, mock.Anything).Return(nil) - pipelineLockStub := &traceMocks.PipelineLock{} + pipelineLockStub := &mocks.PipelineLock{} pipelineLockStub.On("TryAcquireLock", mock.Anything, mock.Anything).Return(nil) pipelineLockStub.On("IsLockHolder", mock.Anything, mock.Anything).Return(nil) @@ -959,7 +959,7 @@ func TestReconcile(t *testing.T) { gatewayProberStub := commonStatusStubs.NewDeploymentSetProber(tt.probeGatewayErr) - flowHealthProberStub := &traceMocks.FlowHealthProber{} + flowHealthProberStub := &mocks.FlowHealthProber{} flowHealthProberStub.On("Probe", mock.Anything, pipeline.Name).Return(prober.OTelPipelineProbeResult{}, nil) errToMsg := &conditions.ErrorToMessageConverter{}