@@ -23,6 +23,11 @@ def test_metrics_list(self):
2323 """Check if setup was done correctly."""
2424 metrics_list = self .pc .all_metrics ()
2525 self .assertTrue (len (metrics_list ) > 0 , "no metrics received from prometheus" )
26+ # Checking that the results of all_metrics() and get_label_values("__name__") are the same.
27+ self .assertEqual (metrics_list , self .pc .get_label_values ("__name__" ))
28+ # Check for the "job" label.
29+ label_values = self .pc .get_label_values ("job" )
30+ self .assertTrue (len (label_values ) > 0 , "no metrics received from prometheus" )
2631
2732 def test_get_metric_range_data (self ): # noqa D102
2833 start_time = datetime .now () - timedelta (minutes = 10 )
@@ -159,11 +164,20 @@ def test_unauthorized(self): # noqa D102
159164 self .pc .all_metrics ()
160165 self .assertEqual ("HTTP Status Code 403 (b'Unauthorized')" , str (exc .exception ))
161166
167+ with self .mock_response ("Unauthorized" , status_code = 403 ):
168+ with self .assertRaises (PrometheusApiClientException ) as exc :
169+ self .pc .get_label_values ("label_name" )
170+ self .assertEqual ("HTTP Status Code 403 (b'Unauthorized')" , str (exc .exception ))
171+
162172 def test_broken_responses (self ): # noqa D102
163173 with self .assertRaises (PrometheusApiClientException ) as exc :
164174 self .pc .all_metrics ()
165175 self .assertEqual ("HTTP Status Code 403 (b'BOOM!')" , str (exc .exception ))
166176
177+ with self .assertRaises (PrometheusApiClientException ) as exc :
178+ self .pc .get_label_values ("label_name" )
179+ self .assertEqual ("HTTP Status Code 403 (b'BOOM!')" , str (exc .exception ))
180+
167181 with self .assertRaises (PrometheusApiClientException ) as exc :
168182 self .pc .get_current_metric_value ("metric" )
169183 self .assertEqual ("HTTP Status Code 403 (b'BOOM!')" , str (exc .exception ))
@@ -196,3 +210,12 @@ def test_all_metrics_method(self): # noqa D102
196210 self .assertEqual (handler .call_count , 1 )
197211 request = handler .requests [0 ]
198212 self .assertEqual (request .path_url , "/api/v1/label/__name__/values" )
213+
214+ def test_get_label_values_method (self ): # noqa D102
215+ all_metrics_payload = {"status" : "success" , "data" : ["value1" , "value2" ]}
216+
217+ with self .mock_response (all_metrics_payload ) as handler :
218+ self .assertTrue (len (self .pc .get_label_values ("label_name" )))
219+ self .assertEqual (handler .call_count , 1 )
220+ request = handler .requests [0 ]
221+ self .assertEqual (request .path_url , "/api/v1/label/label_name/values" )
0 commit comments