From 9cb55939a5f4b0c20e779d7c7cf99fc9e941275e Mon Sep 17 00:00:00 2001 From: Josh Orr Date: Sat, 18 Feb 2023 17:03:00 -0700 Subject: [PATCH] feat: by default use `all` for all environments, instead of nothing. --- tests/normal_tests/test_config.py | 40 +++++++++++++++++++++++++++++++ xcon/conf.py | 4 ++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/tests/normal_tests/test_config.py b/tests/normal_tests/test_config.py index f8b69e1..f6860a8 100644 --- a/tests/normal_tests/test_config.py +++ b/tests/normal_tests/test_config.py @@ -626,3 +626,43 @@ def test_dynamo_cacher_retrieves_new_values_after_local_cache_expires(directory: # Removed the external dynamo cacher items from its table, and see if we get the new value now # (as it will now consult with ssm provider which should re-lookup the value due to expire). assert config.get('exp_test_value', ignore_local_caches=True) == 'expiringTestValue2' + + +@Config(providers=DEFAULT_TESTING_PROVIDERS) +def test_directory_order_followed(): + s = xcon_settings.service + e = xcon_settings.environment + + boto_clients.ssm.put_parameter(Name='/global/all/testv', Value="/g/a", Type="String") + assert config['testv'] == "/g/a" + + boto_clients.ssm.put_parameter(Name=f'/global/{e}/testv', Value="/g/e", Type="String") + with InternalLocalProviderCache(): + assert config['testv'] == "/g/e" + + boto_clients.ssm.put_parameter(Name=f'/{s}/all/testv', Value="/s/a", Type="String") + with InternalLocalProviderCache(): + assert config['testv'] == "/s/a" + + boto_clients.ssm.put_parameter(Name=f'/{s}/{e}/testv', Value="/s/e", Type="String") + with InternalLocalProviderCache(): + assert config['testv'] == "/s/e" + + # Cache is still here, it only originally saw '/g/a' + assert config['testv'] == "/g/a" + + InternalLocalProviderCache.grab().reset_cache() + + assert config['testv'] == "/s/e" + + config.directories = [ + "/global/all/", + "/{service}/{environment}" + ] + + assert config['testv'] == "/g/a" + + config.directories = Default + assert config['testv'] == "/s/e" + + diff --git a/xcon/conf.py b/xcon/conf.py index 22b1eef..9195025 100644 --- a/xcon/conf.py +++ b/xcon/conf.py @@ -53,9 +53,9 @@ def __init__(self): directories: Sequence[Directory] = ( Directory('/{service}/{environment}'), - Directory('/{service}'), + Directory('/{service}/all'), Directory('/global/{environment}'), - Directory('/global'), + Directory('/global/all'), ) """ Default list of directories to use.