diff --git a/pkg/controller/podautoscaler/horizontal_test.go b/pkg/controller/podautoscaler/horizontal_test.go index 2d74a8aef9e..b9d89c86204 100644 --- a/pkg/controller/podautoscaler/horizontal_test.go +++ b/pkg/controller/podautoscaler/horizontal_test.go @@ -124,6 +124,7 @@ type testCase struct { testClient *fake.Clientset testMetricsClient *metricsfake.Clientset testCMClient *cmfake.FakeCustomMetricsClient + testEMClient *emfake.FakeExternalMetricsClient testScaleClient *scalefake.FakeScaleClient } @@ -582,6 +583,9 @@ func (tc *testCase) setupController(t *testing.T) (*HorizontalController, inform if tc.testCMClient != nil { testCMClient = tc.testCMClient } + if tc.testEMClient != nil { + testEMClient = tc.testEMClient + } if tc.testScaleClient != nil { testScaleClient = tc.testScaleClient } @@ -1568,6 +1572,16 @@ func TestConditionFailedGetMetrics(t *testing.T) { }, }, }, + "FailedGetExternalMetric": { + { + Type: autoscalingv2.ExternalMetricSourceType, + External: &autoscalingv2.ExternalMetricSource{ + MetricSelector: &metav1.LabelSelector{}, + MetricName: "qps", + TargetValue: resource.NewMilliQuantity(300, resource.DecimalSI), + }, + }, + }, } for reason, specs := range metricsTargets { @@ -1581,9 +1595,10 @@ func TestConditionFailedGetMetrics(t *testing.T) { reportedCPURequests: []resource.Quantity{resource.MustParse("0.1"), resource.MustParse("0.1"), resource.MustParse("0.1")}, useMetricsAPI: true, } - _, testMetricsClient, testCMClient, _, _ := tc.prepareTestClient(t) + _, testMetricsClient, testCMClient, testEMClient, _ := tc.prepareTestClient(t) tc.testMetricsClient = testMetricsClient tc.testCMClient = testCMClient + tc.testEMClient = testEMClient testMetricsClient.PrependReactor("list", "pods", func(action core.Action) (handled bool, ret runtime.Object, err error) { return true, &metricsapi.PodMetricsList{}, fmt.Errorf("something went wrong") @@ -1591,6 +1606,9 @@ func TestConditionFailedGetMetrics(t *testing.T) { testCMClient.PrependReactor("get", "*", func(action core.Action) (handled bool, ret runtime.Object, err error) { return true, &cmapi.MetricValueList{}, fmt.Errorf("something went wrong") }) + testEMClient.PrependReactor("list", "*", func(action core.Action) (handled bool, ret runtime.Object, err error) { + return true, &emapi.ExternalMetricValueList{}, fmt.Errorf("something went wrong") + }) tc.expectedConditions = []autoscalingv1.HorizontalPodAutoscalerCondition{ {Type: autoscalingv1.AbleToScale, Status: v1.ConditionTrue, Reason: "SucceededGetScale"},