From d75fd8215942fbc6f1dcc4e6fb2310bc4460736e Mon Sep 17 00:00:00 2001 From: Karol Wychowaniec Date: Mon, 16 Oct 2017 13:37:59 +0200 Subject: [PATCH] Fix expected result in Custom Metrics - Stackdriver Adapter e2e test --- .../monitoring/custom_metrics_stackdriver.go | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/test/e2e/instrumentation/monitoring/custom_metrics_stackdriver.go b/test/e2e/instrumentation/monitoring/custom_metrics_stackdriver.go index f21e6136560..8b615296937 100644 --- a/test/e2e/instrumentation/monitoring/custom_metrics_stackdriver.go +++ b/test/e2e/instrumentation/monitoring/custom_metrics_stackdriver.go @@ -121,11 +121,22 @@ func testAdapter(f *framework.Framework, kubeClient clientset.Interface, customM if err != nil { framework.Failf("Failed to retrieve a list of supported metrics: %s", err) } + gotCustomMetric, gotUnusedMetric := false, false for _, resource := range resources.APIResources { - if resource.Name != "pods/"+CustomMetricName && resource.Name != "pods/"+UnusedMetricName { + if resource.Name == "pods/"+CustomMetricName { + gotCustomMetric = true + } else if resource.Name == "pods/"+UnusedMetricName { + gotUnusedMetric = true + } else { framework.Failf("Unexpected metric %s. Only metric %s should be supported", resource.Name, CustomMetricName) } } + if !gotCustomMetric { + framework.Failf("Metric '%s' expected but not received", CustomMetricName) + } + if !gotUnusedMetric { + framework.Failf("Metric '%s' expected but not received", UnusedMetricName) + } value, err := customMetricsClient.NamespacedMetrics(f.Namespace.Name).GetForObject(schema.GroupKind{Group: "", Kind: "Pod"}, stackdriverExporterPod1, CustomMetricName) if err != nil { framework.Failf("Failed query: %s", err) @@ -141,14 +152,11 @@ func testAdapter(f *framework.Framework, kubeClient clientset.Interface, customM if err != nil { framework.Failf("Failed query: %s", err) } - if len(values.Items) != 2 { - framework.Failf("Expected results for exactly 2 pods, but %v results received", len(values.Items)) + if len(values.Items) != 1 { + framework.Failf("Expected results for exactly 1 pod, but %v results received", len(values.Items)) } - for _, value := range values.Items { - if (value.DescribedObject.Name == stackdriverExporterPod1 && value.Value.Value() != CustomMetricValue) || - (value.DescribedObject.Name == stackdriverExporterPod2 && value.Value.Value() != UnusedMetricValue) { - framework.Failf("Unexpected metric value for metric %s and pod %s: %v", CustomMetricName, value.DescribedObject.Name, value.Value.Value()) - } + if values.Items[0].DescribedObject.Name != stackdriverExporterPod1 || values.Items[0].Value.Value() != CustomMetricValue { + framework.Failf("Unexpected metric value for metric %s and pod %s: %v", CustomMetricName, values.Items[0].DescribedObject.Name, values.Items[0].Value.Value()) } }