summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2021-04-14 13:16:39 +0100
committerStephen Finucane <sfinucan@redhat.com>2021-04-14 13:16:39 +0100
commit068c13547ed0c8bdd55f338fe9d8386fe02e6c0d (patch)
tree9ba6c18d048afac592510c54d45d20218e0114ef
parentcfa256464e519468f227e676e2ca0829bf5c7e02 (diff)
downloadoslo-config-068c13547ed0c8bdd55f338fe9d8386fe02e6c0d.tar.gz
tests: Add test for config file priority order
This was documented in the docstring but we had nothing to assert it in tests. Correct that gap. Change-Id: I4002e7fe18c43eb5f9ba2eae16022d7da87f790d Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
-rw-r--r--oslo_config/tests/test_cfg.py45
1 files changed, 39 insertions, 6 deletions
diff --git a/oslo_config/tests/test_cfg.py b/oslo_config/tests/test_cfg.py
index 505cb00..0686eca 100644
--- a/oslo_config/tests/test_cfg.py
+++ b/oslo_config/tests/test_cfg.py
@@ -264,8 +264,10 @@ class HelpTestCase(BaseTestCase):
class FindConfigFilesTestCase(BaseTestCase):
def test_find_config_files(self):
- config_files = [os.path.expanduser('~/.blaa/blaa.conf'),
- '/etc/foo.conf']
+ config_files = [
+ os.path.expanduser('~/.blaa/blaa.conf'),
+ '/etc/foo.conf',
+ ]
self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo']))
self.useFixture(fixtures.MonkeyPatch('os.path.exists',
@@ -273,11 +275,42 @@ class FindConfigFilesTestCase(BaseTestCase):
self.assertEqual(cfg.find_config_files(project='blaa'), config_files)
+ def test_find_config_files_overrides(self):
+ """Ensure priority of directories is enforced.
+
+ Ensure we will only ever return two files: $project.conf and
+ $prog.conf.
+ """
+ config_files = [
+ os.path.expanduser('~/.foo/foo.conf'),
+ # no '~/.foo/bar.conf' to make sure we fall through
+ os.path.expanduser('~/foo.conf'),
+ os.path.expanduser('~/bar.conf'),
+ '/etc/foo/foo.conf',
+ '/etc/foo/bar.conf',
+ '/etc/foo.conf',
+ '/etc/bar.conf',
+ ]
+
+ self.useFixture(fixtures.MonkeyPatch(
+ 'os.path.exists', lambda p: p in config_files))
+
+ expected = [
+ os.path.expanduser('~/.foo/foo.conf'),
+ os.path.expanduser('~/bar.conf'),
+ ]
+ actual = cfg.find_config_files(project='foo', prog='bar')
+ self.assertEqual(expected, actual)
+
def test_find_config_files_snap(self):
- config_files = ['/snap/nova/current/etc/blaa/blaa.conf',
- '/var/snap/nova/common/etc/blaa/blaa.conf']
- fake_env = {'SNAP': '/snap/nova/current/',
- 'SNAP_COMMON': '/var/snap/nova/common/'}
+ config_files = [
+ '/snap/nova/current/etc/blaa/blaa.conf',
+ '/var/snap/nova/common/etc/blaa/blaa.conf',
+ ]
+ fake_env = {
+ 'SNAP': '/snap/nova/current/',
+ 'SNAP_COMMON': '/var/snap/nova/common/',
+ }
self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo']))
self.useFixture(fixtures.MonkeyPatch('os.path.exists',