diff --git a/pkg/scaling/scale_handler_test.go b/pkg/scaling/scale_handler_test.go index 65704709eee..33d0f7ed8fe 100644 --- a/pkg/scaling/scale_handler_test.go +++ b/pkg/scaling/scale_handler_test.go @@ -62,7 +62,6 @@ func TestGetScaledObjectMetrics_DirectCall(t *testing.T) { recorder := record.NewFakeRecorder(1) mockClient := mock_client.NewMockClient(ctrl) mockExecutor := mock_executor.NewMockScaleExecutor(ctrl) - //mockStatusWriter := mock_client.NewMockStatusWriter(ctrl) metricsSpecs := []v2.MetricSpec{createMetricSpec(10, metricName)} metricValue := scalers.GenerateMetricInMili(metricName, float64(10)) @@ -130,8 +129,7 @@ func TestGetScaledObjectMetrics_DirectCall(t *testing.T) { mockExecutor.EXPECT().RequestScale(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) sh.checkScalers(context.TODO(), &scaledObject, &sync.RWMutex{}) - //mockClient.EXPECT().Status().Return(mockStatusWriter) - //mockStatusWriter.EXPECT().Patch(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) + expectNoStatusPatch(ctrl) scaler.EXPECT().GetMetricSpecForScaling(gomock.Any()).Return(metricsSpecs) // hitting directly GetMetricsAndActivity() scaler.EXPECT().GetMetricsAndActivity(gomock.Any(), gomock.Any()).Return([]external_metrics.ExternalMetricValue{metricValue}, true, nil) @@ -153,7 +151,6 @@ func TestGetScaledObjectMetrics_FromCache(t *testing.T) { recorder := record.NewFakeRecorder(1) mockClient := mock_client.NewMockClient(ctrl) mockExecutor := mock_executor.NewMockScaleExecutor(ctrl) - //mockStatusWriter := mock_client.NewMockStatusWriter(ctrl) metricsSpecs := []v2.MetricSpec{createMetricSpec(10, metricName)} metricValue := scalers.GenerateMetricInMili(metricName, float64(10)) @@ -221,8 +218,7 @@ func TestGetScaledObjectMetrics_FromCache(t *testing.T) { mockExecutor.EXPECT().RequestScale(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) sh.checkScalers(context.TODO(), &scaledObject, &sync.RWMutex{}) - //mockClient.EXPECT().Status().Return(mockStatusWriter) - //mockStatusWriter.EXPECT().Patch(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) + expectNoStatusPatch(ctrl) scaler.EXPECT().GetMetricSpecForScaling(gomock.Any()).Return(metricsSpecs) // hitting cache here instead of calling GetMetricsAndActivity() metrics, err := sh.GetScaledObjectMetrics(context.TODO(), scaledObjectName, scaledObjectNamespace, metricName) @@ -259,7 +255,6 @@ func TestGetScaledObjectMetrics_InParallel(t *testing.T) { recorder := record.NewFakeRecorder(1) mockClient := mock_client.NewMockClient(ctrl) mockExecutor := mock_executor.NewMockScaleExecutor(ctrl) - //mockStatusWriter := mock_client.NewMockStatusWriter(ctrl) scalerCollection := []*mock_scalers.MockScaler{} @@ -353,8 +348,8 @@ func TestGetScaledObjectMetrics_InParallel(t *testing.T) { return true }, 1*time.Second, 400*time.Millisecond, "timeout exceeded: scalers not processed in parallel during `checkScalers`") - //mockClient.EXPECT().Status().Times(len(metricNames)).Return(mockStatusWriter) - //mockStatusWriter.EXPECT().Patch(gomock.Any(), gomock.Any(), gomock.Any()).Times(len(metricNames)).Return(nil) + expectNoStatusPatch(ctrl) + for i := 0; i < len(metricNames); i++ { i := i scalerCollection[i].EXPECT().GetMetricSpecForScaling(gomock.Any()).Return(metricsSpecFn(i)) @@ -907,7 +902,6 @@ func TestScalingModifiersFormula(t *testing.T) { recorder := record.NewFakeRecorder(1) mockClient := mock_client.NewMockClient(ctrl) mockExecutor := mock_executor.NewMockScaleExecutor(ctrl) - //mockStatusWriter := mock_client.NewMockStatusWriter(ctrl) metricsSpecs1 := []v2.MetricSpec{createMetricSpec(2, metricName1)} metricsSpecs2 := []v2.MetricSpec{createMetricSpec(5, metricName2)} @@ -998,8 +992,8 @@ func TestScalingModifiersFormula(t *testing.T) { mockExecutor.EXPECT().RequestScale(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) sh.checkScalers(context.TODO(), &scaledObject, &sync.RWMutex{}) - //mockClient.EXPECT().Status().Return(mockStatusWriter).Times(2) - //mockStatusWriter.EXPECT().Patch(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(2) + expectNoStatusPatch(ctrl) + scaler1.EXPECT().GetMetricSpecForScaling(gomock.Any()).Return(metricsSpecs1) scaler2.EXPECT().GetMetricSpecForScaling(gomock.Any()).Return(metricsSpecs2) scaler1.EXPECT().GetMetricsAndActivity(gomock.Any(), gomock.Any()).Return([]external_metrics.ExternalMetricValue{metricValue1, metricValue2}, true, nil) @@ -1023,3 +1017,8 @@ func createMetricSpec(averageValue int64, metricName string) v2.MetricSpec { }, } } + +func expectNoStatusPatch(ctrl *gomock.Controller) { + statusWriter := mock_client.NewMockStatusWriter(ctrl) + statusWriter.EXPECT().Patch(gomock.Any(), gomock.Any(), gomock.Any()).Times(0) +}