Add test for FailedGetExternalMetric

This commit is contained in:
Beata Skiba 2018-03-19 15:22:36 +01:00
parent ebae09e741
commit dd24087aa3

View File

@ -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"},