Skip to content

Commit

Permalink
add unit test for endpoint resolution caching
Browse files Browse the repository at this point in the history
  • Loading branch information
David Miller committed Sep 29, 2022
1 parent 5aa876e commit a9ca7f9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/unit/test_endpoint_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import json
import logging
import os
import unittest

import pytest

Expand Down Expand Up @@ -343,3 +344,24 @@ def test_ruleset_unknown_parameter_type_raises(partitions):
partitions=partitions,
)
assert "Unknown parameter type: list." in str(exc_info.value)


@pytest.fixture(scope="class")
def test_endpoint_provider(endpoint_provider, request):
request.cls.endpoint_provider = endpoint_provider


@pytest.mark.usefixtures("test_endpoint_provider")
class EndpointProviderCacheTestCase(unittest.TestCase):
@unittest.mock.patch("botocore.endpoint_provider.RuleSet.evaluate")
def test_endpoint_resolution_caches(self, mock_evaluate):

for _ in range(5):
self.endpoint_provider.resolve_endpoint(**{"Region": "us-east-1"})
mock_evaluate.assert_called_once_with({"Region": "us-east-1"})
mock_evaluate.reset_mock()

regions = ["us-west-2", "us-west-1"]
for region in regions:
self.endpoint_provider.resolve_endpoint(**{"Region": region})
self.assertEqual(mock_evaluate.call_count, 2)

0 comments on commit a9ca7f9

Please sign in to comment.