mirror of https://github.com/ansible/ansible.git
parent
80b0e0e05a
commit
12c8dd1893
@ -0,0 +1,4 @@
|
|||||||
|
[defaults]
|
||||||
|
inikey=fromini
|
||||||
|
matterless=lessfromini
|
||||||
|
mattermore=morefromini
|
@ -0,0 +1,55 @@
|
|||||||
|
# mock config defs with diff use cases
|
||||||
|
config_entry: &entry
|
||||||
|
name: test config
|
||||||
|
default: DEFAULT
|
||||||
|
description:
|
||||||
|
- This does nothing, its for testing
|
||||||
|
env:
|
||||||
|
- name: ENVVAR
|
||||||
|
ini:
|
||||||
|
- section: defaults
|
||||||
|
key: inikey
|
||||||
|
type: string
|
||||||
|
config_entry_multi: &entry_multi
|
||||||
|
name: has more than one entry per config source
|
||||||
|
default: DEFAULT
|
||||||
|
description:
|
||||||
|
- This does nothing, its for testing
|
||||||
|
env:
|
||||||
|
- name: MATTERLESS
|
||||||
|
- name: MATTERMORE
|
||||||
|
ini:
|
||||||
|
- section: defaults
|
||||||
|
key: matterless
|
||||||
|
- section: defaults
|
||||||
|
key: mattermore
|
||||||
|
type: string
|
||||||
|
config_entry_bool:
|
||||||
|
<<: *entry
|
||||||
|
type: bool
|
||||||
|
default: False
|
||||||
|
config_entry_list:
|
||||||
|
<<: *entry
|
||||||
|
type: list
|
||||||
|
default: [DEFAULT]
|
||||||
|
config_entry_deprecated:
|
||||||
|
<<: *entry
|
||||||
|
deprecated: &dep
|
||||||
|
why: 'cause i wanna'
|
||||||
|
version: 9.2
|
||||||
|
alternative: 'none whatso ever'
|
||||||
|
config_entry_multi_deprecated:
|
||||||
|
<<: *entry_multi
|
||||||
|
deprecated: *dep
|
||||||
|
config_entry_multi_deprecated_source:
|
||||||
|
<<: *entry_multi
|
||||||
|
env:
|
||||||
|
- name: MATTERLESS
|
||||||
|
deprecated: *dep
|
||||||
|
- name: MATTERMORE
|
||||||
|
ini:
|
||||||
|
- section: defaults
|
||||||
|
key: matterless
|
||||||
|
deprecated: *dep
|
||||||
|
- section: defaults
|
||||||
|
key: mattermore
|
@ -0,0 +1,4 @@
|
|||||||
|
[defaults]
|
||||||
|
inikey=fromini2
|
||||||
|
matterless=lessfromini2
|
||||||
|
mattermore=morefromini2
|
@ -0,0 +1,41 @@
|
|||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
from ansible.compat.tests import unittest
|
||||||
|
|
||||||
|
from ansible.config.data import ConfigData
|
||||||
|
from ansible.config.manager import Setting
|
||||||
|
|
||||||
|
|
||||||
|
mykey = Setting('mykey', 'myvalue', 'test', 'string')
|
||||||
|
mykey2 = Setting('mykey2', 'myvalue2', ['test', 'test2'], 'list')
|
||||||
|
mykey3 = Setting('mykey3', 'myvalue3', 11111111111, 'integer')
|
||||||
|
|
||||||
|
|
||||||
|
class TestConfigData(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.cdata = ConfigData()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.cdata = None
|
||||||
|
|
||||||
|
def test_update_setting(self):
|
||||||
|
for setting in [mykey, mykey2, mykey3]:
|
||||||
|
self.cdata.update_setting(setting)
|
||||||
|
self.assertEqual(setting, self.cdata._global_settings.get(setting.name))
|
||||||
|
|
||||||
|
def test_update_setting_with_plugin(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_get_setting(self):
|
||||||
|
self.cdata._global_settings = {'mykey': mykey}
|
||||||
|
self.assertEqual(mykey, self.cdata.get_setting('mykey'))
|
||||||
|
|
||||||
|
def test_get_settings(self):
|
||||||
|
all_settings = {'mykey': mykey, 'mykey2': mykey2}
|
||||||
|
self.cdata._global_settings = all_settings
|
||||||
|
|
||||||
|
for setting in self.cdata.get_settings():
|
||||||
|
self.assertEqual(all_settings[setting.name], setting)
|
@ -0,0 +1,47 @@
|
|||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from ansible.compat.tests import unittest
|
||||||
|
|
||||||
|
from ansible.config.manager import ConfigManager, Setting
|
||||||
|
|
||||||
|
curdir = os.path.dirname(__file__)
|
||||||
|
cfg_file = os.path.join(curdir, 'test.cfg')
|
||||||
|
cfg_file2 = os.path.join(curdir, 'test2.cfg')
|
||||||
|
|
||||||
|
expected_ini = {'CONFIG_FILE': Setting(name='CONFIG_FILE', value=cfg_file, origin='', type='string'),
|
||||||
|
'config_entry': Setting(name='config_entry', value=u'fromini', origin=cfg_file, type='string'),
|
||||||
|
'config_entry_bool': Setting(name='config_entry_bool', value=False, origin=cfg_file, type='bool'),
|
||||||
|
'config_entry_list': Setting(name='config_entry_list', value=['fromini'], origin=cfg_file, type='list'),
|
||||||
|
'config_entry_deprecated': Setting(name='config_entry_deprecated', value=u'fromini', origin=cfg_file, type='string'),
|
||||||
|
'config_entry_multi': Setting(name='config_entry_multi', value=u'morefromini', origin=cfg_file, type='string'),
|
||||||
|
'config_entry_multi_deprecated': Setting(name='config_entry_multi_deprecated', value=u'morefromini', origin=cfg_file, type='string'),
|
||||||
|
'config_entry_multi_deprecated_source': Setting(name='config_entry_multi_deprecated_source', value=u'morefromini',
|
||||||
|
origin=cfg_file, type='string')}
|
||||||
|
|
||||||
|
|
||||||
|
class TestConfigData(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.manager = ConfigManager(os.path.join(curdir, 'test.cfg'), os.path.join(curdir, 'test.yml'))
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.manager = None
|
||||||
|
|
||||||
|
def test_initial_load(self):
|
||||||
|
self.assertEquals(self.manager.data._global_settings, expected_ini)
|
||||||
|
|
||||||
|
def test_value_and_origin_from_ini(self):
|
||||||
|
self.assertEquals(self.manager.get_config_value_and_origin('config_entry'), ('fromini', cfg_file))
|
||||||
|
|
||||||
|
def test_value_from_ini(self):
|
||||||
|
self.assertEquals(self.manager.get_config_value('config_entry'), 'fromini')
|
||||||
|
|
||||||
|
def test_value_and_origin_from_alt_ini(self):
|
||||||
|
self.assertEquals(self.manager.get_config_value_and_origin('config_entry', cfile=cfg_file2), ('fromini2', cfg_file2))
|
||||||
|
|
||||||
|
def test_value_from_alt_ini(self):
|
||||||
|
self.assertEquals(self.manager.get_config_value('config_entry', cfile=cfg_file2), 'fromini2')
|
Loading…
Reference in New Issue