1+ import os
12import ssl
23from copy import deepcopy
34from typing import Any , Callable , Dict # noqa: F401
1415ssl ._create_default_https_context = ssl ._create_unverified_context
1516
1617
17- @pytest .mark .unit
18+ @pytest .mark .unit
1819def test_instance_additional_check (aggregator , dd_run_check , mock_http_response ):
20+ # Load test data
21+ f_name = os .path .join (os .path .dirname (__file__ ), "data" , "metrics.txt" )
22+ with open (f_name , "r" ) as f :
23+ text_data = f .read ()
24+
25+ # Mock the HTTP response
26+ mock_http_response (text_data , status_code = 200 , headers = {"Content-Type" : "text/plain" })
27+
1928 # add additional metric groups for validation
2029 additional_metric_groups = ["REDIS2.DISK" , "REDIS2.REPLICATION" , "REDIS2.SEARCH" ]
2130 instance = deepcopy (INSTANCE )
@@ -37,6 +46,14 @@ def test_instance_additional_check(aggregator, dd_run_check, mock_http_response)
3746
3847@pytest .mark .unit
3948def test_instance_all_additional_check (aggregator , dd_run_check , mock_http_response ):
49+ # Load test data
50+ f_name = os .path .join (os .path .dirname (__file__ ), "data" , "metrics.txt" )
51+ with open (f_name , "r" ) as f :
52+ text_data = f .read ()
53+
54+ # Mock the HTTP response
55+ mock_http_response (text_data , status_code = 200 , headers = {"Content-Type" : "text/plain" })
56+
4057 # add additional metric groups for validation
4158 additional_metric_groups = [
4259 "REDIS2.REPLICATION" ,
@@ -70,6 +87,14 @@ def test_instance_all_additional_check(aggregator, dd_run_check, mock_http_respo
7087
7188@pytest .mark .unit
7289def test_instance_exclude_metrics (aggregator , dd_run_check , mock_http_response ):
90+ # Load test data
91+ f_name = os .path .join (os .path .dirname (__file__ ), "data" , "metrics.txt" )
92+ with open (f_name , "r" ) as f :
93+ text_data = f .read ()
94+
95+ # Mock the HTTP response
96+ mock_http_response (text_data , status_code = 200 , headers = {"Content-Type" : "text/plain" })
97+
7398 # validate exclude_metrics are not present in metrics
7499 exclude_metrics = ["endpoint_client_connections" , "redis_server_up" ]
75100 instance = deepcopy (INSTANCE )
@@ -90,6 +115,14 @@ def test_end_to_end():
90115
91116@pytest .mark .unit
92117def test_instance_invalid_group_check (aggregator , dd_run_check , mock_http_response ):
118+ # Load test data
119+ f_name = os .path .join (os .path .dirname (__file__ ), "data" , "metrics.txt" )
120+ with open (f_name , "r" ) as f :
121+ text_data = f .read ()
122+
123+ # Mock the HTTP response
124+ mock_http_response (text_data , status_code = 200 , headers = {"Content-Type" : "text/plain" })
125+
93126 instance = deepcopy (INSTANCE )
94127 instance ["metric_groups" ] = ["redis.bogus" , "redis.raft" ]
95128
@@ -105,6 +138,14 @@ def test_instance_invalid_group_check(aggregator, dd_run_check, mock_http_respon
105138
106139@pytest .mark .unit
107140def test_invalid_instance (aggregator , dd_run_check , mock_http_response ):
141+ # Load test data
142+ f_name = os .path .join (os .path .dirname (__file__ ), "data" , "metrics.txt" )
143+ with open (f_name , "r" ) as f :
144+ text_data = f .read ()
145+
146+ # Mock the HTTP response
147+ mock_http_response (text_data , status_code = 200 , headers = {"Content-Type" : "text/plain" })
148+
108149 instance = deepcopy (ERSATZ_INSTANCE )
109150 instance .pop ("openmetrics_endpoint" )
110151
0 commit comments