summaryrefslogtreecommitdiffstats
path: root/test/units/config
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:55:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:55:42 +0000
commit62d9962ec7d01c95bf5732169320d3857a41446e (patch)
treef60d8fc63ff738e5f5afec48a84cf41480ee1315 /test/units/config
parentReleasing progress-linux version 2.14.13-1~progress7.99u1. (diff)
downloadansible-core-62d9962ec7d01c95bf5732169320d3857a41446e.tar.xz
ansible-core-62d9962ec7d01c95bf5732169320d3857a41446e.zip
Merging upstream version 2.16.5.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/units/config')
-rw-r--r--test/units/config/manager/test_find_ini_config_file.py67
-rw-r--r--test/units/config/test3.cfg4
-rw-r--r--test/units/config/test_manager.py30
3 files changed, 60 insertions, 41 deletions
diff --git a/test/units/config/manager/test_find_ini_config_file.py b/test/units/config/manager/test_find_ini_config_file.py
index df41138..e67eecd 100644
--- a/test/units/config/manager/test_find_ini_config_file.py
+++ b/test/units/config/manager/test_find_ini_config_file.py
@@ -13,7 +13,7 @@ import stat
import pytest
from ansible.config.manager import find_ini_config_file
-from ansible.module_utils._text import to_text
+from ansible.module_utils.common.text.converters import to_text
real_exists = os.path.exists
real_isdir = os.path.isdir
@@ -28,22 +28,17 @@ cfg_in_homedir = os.path.expanduser('~/.ansible.cfg')
@pytest.fixture
-def setup_env(request):
+def setup_env(request, monkeypatch):
cur_config = os.environ.get('ANSIBLE_CONFIG', None)
cfg_path = request.param[0]
if cfg_path is None and cur_config:
- del os.environ['ANSIBLE_CONFIG']
+ monkeypatch.delenv('ANSIBLE_CONFIG')
else:
- os.environ['ANSIBLE_CONFIG'] = request.param[0]
+ monkeypatch.setenv('ANSIBLE_CONFIG', request.param[0])
yield
- if cur_config is None and cfg_path:
- del os.environ['ANSIBLE_CONFIG']
- else:
- os.environ['ANSIBLE_CONFIG'] = cur_config
-
@pytest.fixture
def setup_existing_files(request, monkeypatch):
@@ -54,10 +49,8 @@ def setup_existing_files(request, monkeypatch):
return False
def _os_access(path, access):
- if to_text(path) in (request.param[0]):
- return True
- else:
- return False
+ assert to_text(path) in (request.param[0])
+ return True
# Enable user and system dirs so that we know cwd takes precedence
monkeypatch.setattr("os.path.exists", _os_path_exists)
@@ -162,13 +155,11 @@ class TestFindIniFile:
real_stat = os.stat
def _os_stat(path):
- if path == working_dir:
- from posix import stat_result
- stat_info = list(real_stat(path))
- stat_info[stat.ST_MODE] |= stat.S_IWOTH
- return stat_result(stat_info)
- else:
- return real_stat(path)
+ assert path == working_dir
+ from posix import stat_result
+ stat_info = list(real_stat(path))
+ stat_info[stat.ST_MODE] |= stat.S_IWOTH
+ return stat_result(stat_info)
monkeypatch.setattr('os.stat', _os_stat)
@@ -187,13 +178,11 @@ class TestFindIniFile:
real_stat = os.stat
def _os_stat(path):
- if path == working_dir:
- from posix import stat_result
- stat_info = list(real_stat(path))
- stat_info[stat.ST_MODE] |= stat.S_IWOTH
- return stat_result(stat_info)
- else:
- return real_stat(path)
+ assert path == working_dir
+ from posix import stat_result
+ stat_info = list(real_stat(path))
+ stat_info[stat.ST_MODE] |= stat.S_IWOTH
+ return stat_result(stat_info)
monkeypatch.setattr('os.stat', _os_stat)
@@ -215,14 +204,14 @@ class TestFindIniFile:
real_stat = os.stat
def _os_stat(path):
- if path == working_dir:
- from posix import stat_result
- stat_info = list(real_stat(path))
- stat_info[stat.ST_MODE] |= stat.S_IWOTH
- return stat_result(stat_info)
- else:
+ if path != working_dir:
return real_stat(path)
+ from posix import stat_result
+ stat_info = list(real_stat(path))
+ stat_info[stat.ST_MODE] |= stat.S_IWOTH
+ return stat_result(stat_info)
+
monkeypatch.setattr('os.stat', _os_stat)
warnings = set()
@@ -240,13 +229,11 @@ class TestFindIniFile:
real_stat = os.stat
def _os_stat(path):
- if path == working_dir:
- from posix import stat_result
- stat_info = list(real_stat(path))
- stat_info[stat.ST_MODE] |= stat.S_IWOTH
- return stat_result(stat_info)
- else:
- return real_stat(path)
+ assert path == working_dir
+ from posix import stat_result
+ stat_info = list(real_stat(path))
+ stat_info[stat.ST_MODE] |= stat.S_IWOTH
+ return stat_result(stat_info)
monkeypatch.setattr('os.stat', _os_stat)
diff --git a/test/units/config/test3.cfg b/test/units/config/test3.cfg
new file mode 100644
index 0000000..dab9295
--- /dev/null
+++ b/test/units/config/test3.cfg
@@ -0,0 +1,4 @@
+[colors]
+unreachable=bright red
+verbose=rgb013
+debug=gray10
diff --git a/test/units/config/test_manager.py b/test/units/config/test_manager.py
index 8ef4043..0848276 100644
--- a/test/units/config/test_manager.py
+++ b/test/units/config/test_manager.py
@@ -10,7 +10,7 @@ import os
import os.path
import pytest
-from ansible.config.manager import ConfigManager, Setting, ensure_type, resolve_path, get_config_type
+from ansible.config.manager import ConfigManager, ensure_type, resolve_path, get_config_type
from ansible.errors import AnsibleOptionsError, AnsibleError
from ansible.module_utils.six import integer_types, string_types
from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode
@@ -18,6 +18,7 @@ from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode
curdir = os.path.dirname(__file__)
cfg_file = os.path.join(curdir, 'test.cfg')
cfg_file2 = os.path.join(curdir, 'test2.cfg')
+cfg_file3 = os.path.join(curdir, 'test3.cfg')
ensure_test_data = [
('a,b', 'list', list),
@@ -65,6 +66,15 @@ ensure_test_data = [
('None', 'none', type(None))
]
+ensure_unquoting_test_data = [
+ ('"value"', '"value"', 'str', 'env'),
+ ('"value"', '"value"', 'str', 'yaml'),
+ ('"value"', 'value', 'str', 'ini'),
+ ('\'value\'', 'value', 'str', 'ini'),
+ ('\'\'value\'\'', '\'value\'', 'str', 'ini'),
+ ('""value""', '"value"', 'str', 'ini')
+]
+
class TestConfigManager:
@classmethod
@@ -79,6 +89,11 @@ class TestConfigManager:
def test_ensure_type(self, value, expected_type, python_type):
assert isinstance(ensure_type(value, expected_type), python_type)
+ @pytest.mark.parametrize("value, expected_value, value_type, origin", ensure_unquoting_test_data)
+ def test_ensure_type_unquoting(self, value, expected_value, value_type, origin):
+ actual_value = ensure_type(value, value_type, origin)
+ assert actual_value == expected_value
+
def test_resolve_path(self):
assert os.path.join(curdir, 'test.yml') == resolve_path('./test.yml', cfg_file)
@@ -142,3 +157,16 @@ class TestConfigManager:
actual_value = ensure_type(vault_var, value_type)
assert actual_value == "vault text"
+
+
+@pytest.mark.parametrize(("key", "expected_value"), (
+ ("COLOR_UNREACHABLE", "bright red"),
+ ("COLOR_VERBOSE", "rgb013"),
+ ("COLOR_DEBUG", "gray10")))
+def test_256color_support(key, expected_value):
+ # GIVEN: a config file containing 256-color values with default definitions
+ manager = ConfigManager(cfg_file3)
+ # WHEN: get config values
+ actual_value = manager.get_config_value(key)
+ # THEN: no error
+ assert actual_value == expected_value