|
18 | 18 | import pytest |
19 | 19 | from botocore import xform_name |
20 | 20 | from botocore.config import Config |
21 | | -from botocore.endpoint_provider import EndpointProvider |
| 21 | +from botocore.endpoint_provider import ( |
| 22 | + S3_UNREFERENCED_PARAMS, |
| 23 | + EndpointProvider, |
| 24 | +) |
22 | 25 | from botocore.exceptions import ( |
23 | 26 | BotoCoreError, |
24 | 27 | ClientError, |
@@ -295,3 +298,34 @@ def builtin_overwriter_handler(builtins, **kwargs): |
295 | 298 | except (ClientError, ResponseParserError): |
296 | 299 | pass |
297 | 300 | assert len(http_stubber.requests) == 0 |
| 301 | + |
| 302 | + |
| 303 | +def _collect_refs_from_rules(rules): |
| 304 | + """Recursively collect all {\"ref\": \"...\"} values from rules.""" |
| 305 | + refs = set() |
| 306 | + if isinstance(rules, dict): |
| 307 | + if 'ref' in rules: |
| 308 | + refs.add(rules['ref']) |
| 309 | + for value in rules.values(): |
| 310 | + refs.update(_collect_refs_from_rules(value)) |
| 311 | + elif isinstance(rules, list): |
| 312 | + for item in rules: |
| 313 | + refs.update(_collect_refs_from_rules(item)) |
| 314 | + return refs |
| 315 | + |
| 316 | + |
| 317 | +@pytest.mark.validates_model |
| 318 | +def test_s3_unreferenced_endpoint_ruleset_params(): |
| 319 | + """Assert that the set of known S3 endpoint ruleset parameters that are |
| 320 | + not used in the rules hasn't changed. These are set in the |
| 321 | + S3_UNREFERENCED_PARAMS constant to prevent them from influencing the cache. |
| 322 | + """ |
| 323 | + ruleset = LOADER.load_service_model('s3', 'endpoint-rule-set-1') |
| 324 | + all_params = set(ruleset['parameters'].keys()) |
| 325 | + referenced = _collect_refs_from_rules(ruleset['rules']) |
| 326 | + unreferenced = all_params - referenced |
| 327 | + assert unreferenced == S3_UNREFERENCED_PARAMS, ( |
| 328 | + "The set of unused S3 endpoints parameters have changed, examine the " |
| 329 | + "implication of this on endpoint caching behavior before updating" |
| 330 | + "S3_UNREFERENCED_PARAMS." |
| 331 | + ) |
0 commit comments