From c5792d4f87517d841347d33efe7cf8f82820c0e2 Mon Sep 17 00:00:00 2001
From: stedif <stefano.difrischia@inaf.it>
Date: Wed, 10 Aug 2022 16:34:19 +0200
Subject: [PATCH] L2SS-780: add further integration tests

---
 .../test_tango_prometheus_client.py           | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/tangostationcontrol/tangostationcontrol/integration_test/default/prometheus/test_tango_prometheus_client.py b/tangostationcontrol/tangostationcontrol/integration_test/default/prometheus/test_tango_prometheus_client.py
index f6ff9d759..20056c494 100644
--- a/tangostationcontrol/tangostationcontrol/integration_test/default/prometheus/test_tango_prometheus_client.py
+++ b/tangostationcontrol/tangostationcontrol/integration_test/default/prometheus/test_tango_prometheus_client.py
@@ -81,6 +81,26 @@ class TestPrometheusClient(BaseIntegrationTestCase):
             if '*' not in e:    # exclude wildcard
                 self.assertNotIn(e, attribute_list)
     
+    def test_label_metric_list(self):
+        """ Test whether the metric label list matches up with the ones defined in the GaugeMetricFamily constructor"""
+        collector = self.setUp()
+        attribute_metrics, scraping_metrics = collector.collect()
+        expected_attribute_labels = ['station', 'device', 'name', 'str_value', 'type', 'x', 'y', 'idx']
+        expected_scraping_labels = ['station', 'device']
+        numpy.testing.assert_equal([*attribute_metrics.samples[0].labels.keys()], expected_attribute_labels)
+        numpy.testing.assert_equal([*scraping_metrics.samples[0].labels.keys()], expected_scraping_labels)
+    
+    def test_collector_metrics_with_devices_in_off(self):
+        """ Test if the metrics are exposed even if devices are in OFF state """
+        device_name = 'stat/recv/1'
+        recv_proxy = TestDeviceProxy(device_name)
+        recv_proxy.off()
+        collector = self.setUp()
+        expected_attrs = ['State', 'Status']    # only state attributes are scraped when device is in OFF
+        metrics = collector.device_metrics(device_name)
+        actual_attrs = [metrics[0][0][2], metrics[1][0][2]]
+        numpy.testing.assert_equal(sorted(actual_attrs), expected_attrs)
+
     def test_collector_metrics(self):
         """ Test if the metrics are correctly exposed """
         device_name = 'stat/recv/1'
-- 
GitLab