@@ -24,18 +24,82 @@ def test_get_no_sampling_rules(self, mock_post=None):
24
24
self .assertTrue (len (sampling_rules ) == 0 )
25
25
26
26
@patch ("requests.post" )
27
- def test_get_invalid_response (self , mock_post = None ):
27
+ def test_get_invalid_responses (self , mock_post = None ):
28
28
mock_post .return_value .configure_mock (** {"json.return_value" : {}})
29
29
client = _AwsXRaySamplingClient ("http://127.0.0.1:2000" )
30
30
with self .assertLogs (_logger , level = "ERROR" ):
31
31
sampling_rules = client .get_sampling_rules ()
32
- self .assertTrue (len (sampling_rules ) == 0 )
32
+ self .assertTrue (len (sampling_rules ) == 0 )
33
+
34
+ @patch ("requests.post" )
35
+ def test_get_sampling_rule_missing_in_records (self , mock_post = None ):
36
+ mock_post .return_value .configure_mock (** {"json.return_value" : {"SamplingRuleRecords" : [{}]}})
37
+ client = _AwsXRaySamplingClient ("http://127.0.0.1:2000" )
38
+ with self .assertLogs (_logger , level = "ERROR" ):
39
+ sampling_rules = client .get_sampling_rules ()
40
+ self .assertTrue (len (sampling_rules ) == 0 )
33
41
34
42
@patch ("requests.post" )
35
- def test_get_two_sampling_rules (self , mock_post = None ):
43
+ def test_default_values_used_when_missing_properties_in_sampling_rule (self , mock_post = None ):
44
+ mock_post .return_value .configure_mock (** {"json.return_value" : {"SamplingRuleRecords" : [{"SamplingRule" : {}}]}})
45
+ client = _AwsXRaySamplingClient ("http://127.0.0.1:2000" )
46
+ sampling_rules = client .get_sampling_rules ()
47
+ self .assertTrue (len (sampling_rules ) == 1 )
48
+
49
+ sampling_rule = sampling_rules [0 ]
50
+ self .assertEqual (sampling_rule .Attributes , {})
51
+ self .assertEqual (sampling_rule .FixedRate , "" )
52
+ self .assertEqual (sampling_rule .HTTPMethod , "" )
53
+ self .assertEqual (sampling_rule .Host , "" )
54
+ self .assertEqual (sampling_rule .Priority , "" )
55
+ self .assertEqual (sampling_rule .ReservoirSize , "" )
56
+ self .assertEqual (sampling_rule .ResourceARN , "" )
57
+ self .assertEqual (sampling_rule .RuleARN , "" )
58
+ self .assertEqual (sampling_rule .RuleName , "" )
59
+ self .assertEqual (sampling_rule .ServiceName , "" )
60
+ self .assertEqual (sampling_rule .ServiceType , "" )
61
+ self .assertEqual (sampling_rule .URLPath , "" )
62
+ self .assertEqual (sampling_rule .Version , "" )
63
+
64
+ @patch ("requests.post" )
65
+ def test_get_three_sampling_rules (self , mock_post = None ):
66
+ sampling_records = []
36
67
with open (f"{ DATA_DIR } /get-sampling-rules-response-sample.json" , encoding = "UTF-8" ) as file :
37
- mock_post .return_value .configure_mock (** {"json.return_value" : json .load (file )})
68
+ sample_response = json .load (file )
69
+ sampling_records = sample_response ["SamplingRuleRecords" ]
70
+ mock_post .return_value .configure_mock (** {"json.return_value" : sample_response })
38
71
file .close ()
39
72
client = _AwsXRaySamplingClient ("http://127.0.0.1:2000" )
40
73
sampling_rules = client .get_sampling_rules ()
41
- self .assertTrue (len (sampling_rules ) == 3 )
74
+ self .assertEqual (len (sampling_rules ), 3 )
75
+ self .assertEqual (len (sampling_rules ), len (sampling_records ))
76
+ self .validate_match_sampling_rules_properties_with_records (sampling_rules , sampling_records )
77
+
78
+ def validate_match_sampling_rules_properties_with_records (self , sampling_rules , sampling_records ):
79
+ for _ , (sampling_rule , sampling_record ) in enumerate (zip (sampling_rules , sampling_records )):
80
+ self .assertIsNotNone (sampling_rule .Attributes )
81
+ self .assertEqual (sampling_rule .Attributes , sampling_record ["SamplingRule" ]["Attributes" ])
82
+ self .assertIsNotNone (sampling_rule .FixedRate )
83
+ self .assertEqual (sampling_rule .FixedRate , sampling_record ["SamplingRule" ]["FixedRate" ])
84
+ self .assertIsNotNone (sampling_rule .HTTPMethod )
85
+ self .assertEqual (sampling_rule .HTTPMethod , sampling_record ["SamplingRule" ]["HTTPMethod" ])
86
+ self .assertIsNotNone (sampling_rule .Host )
87
+ self .assertEqual (sampling_rule .Host , sampling_record ["SamplingRule" ]["Host" ])
88
+ self .assertIsNotNone (sampling_rule .Priority )
89
+ self .assertEqual (sampling_rule .Priority , sampling_record ["SamplingRule" ]["Priority" ])
90
+ self .assertIsNotNone (sampling_rule .ReservoirSize )
91
+ self .assertEqual (sampling_rule .ReservoirSize , sampling_record ["SamplingRule" ]["ReservoirSize" ])
92
+ self .assertIsNotNone (sampling_rule .ResourceARN )
93
+ self .assertEqual (sampling_rule .ResourceARN , sampling_record ["SamplingRule" ]["ResourceARN" ])
94
+ self .assertIsNotNone (sampling_rule .RuleARN )
95
+ self .assertEqual (sampling_rule .RuleARN , sampling_record ["SamplingRule" ]["RuleARN" ])
96
+ self .assertIsNotNone (sampling_rule .RuleName )
97
+ self .assertEqual (sampling_rule .RuleName , sampling_record ["SamplingRule" ]["RuleName" ])
98
+ self .assertIsNotNone (sampling_rule .ServiceName )
99
+ self .assertEqual (sampling_rule .ServiceName , sampling_record ["SamplingRule" ]["ServiceName" ])
100
+ self .assertIsNotNone (sampling_rule .ServiceType )
101
+ self .assertEqual (sampling_rule .ServiceType , sampling_record ["SamplingRule" ]["ServiceType" ])
102
+ self .assertIsNotNone (sampling_rule .URLPath )
103
+ self .assertEqual (sampling_rule .URLPath , sampling_record ["SamplingRule" ]["URLPath" ])
104
+ self .assertIsNotNone (sampling_rule .Version )
105
+ self .assertEqual (sampling_rule .Version , sampling_record ["SamplingRule" ]["Version" ])
0 commit comments