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>
This commit is contained in:
parent
cfa256464e
commit
068c13547e
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user