summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2021-04-21 17:52:59 +0000
committerGerrit Code Review <review@openstack.org>2021-04-21 17:52:59 +0000
commit758775c07bc66db3ee6602ecaec53173e89c5acb (patch)
tree17979b9145c18e1e63ab3d8db845872cef513621
parent117c75be7f92876529d27418073ad1c8720d55bc (diff)
parent068c13547ed0c8bdd55f338fe9d8386fe02e6c0d (diff)
downloadoslo-config-758775c07bc66db3ee6602ecaec53173e89c5acb.tar.gz
Merge "tests: Add test for config file priority order"
-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',