diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 06:24:57 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 06:24:57 +0000 |
commit | 1faea9a6c75f33109e8f66b57b432fdad57b3f46 (patch) | |
tree | 4184ce38ac0cf9d5a46bbbae03c87be82927f12b /test/test_cli_role_paths.py | |
parent | Adding upstream version 6.17.2. (diff) | |
download | ansible-lint-upstream.tar.xz ansible-lint-upstream.zip |
Adding upstream version 24.6.1.upstream/24.6.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/test_cli_role_paths.py')
-rw-r--r-- | test/test_cli_role_paths.py | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/test/test_cli_role_paths.py b/test/test_cli_role_paths.py index 148e1ed..131c3b5 100644 --- a/test/test_cli_role_paths.py +++ b/test/test_cli_role_paths.py @@ -1,4 +1,5 @@ """Tests related to role paths.""" + from __future__ import annotations import os @@ -174,7 +175,10 @@ def test_run_single_role_path_with_roles_path_env(local_test_dir: Path) -> None: @pytest.mark.parametrize( ("result", "env"), - ((True, {"GITHUB_ACTIONS": "true", "GITHUB_WORKFLOW": "foo"}), (False, None)), + ( + (True, {"GITHUB_ACTIONS": "true", "GITHUB_WORKFLOW": "foo", "NO_COLOR": "1"}), + (False, None), + ), ids=("on", "off"), ) def test_run_playbook_github(result: bool, env: dict[str, str]) -> None: @@ -192,3 +196,41 @@ def test_run_playbook_github(result: bool, env: dict[str, str]) -> None: "Package installs should not use latest" ) assert (expected in result_gh.stderr) is result + + +def test_run_role_identified(local_test_dir: Path) -> None: + """Test that role name is identified correctly.""" + cwd = local_test_dir + + env = os.environ.copy() + env["ANSIBLE_ROLES_PATH"] = os.path.realpath( + (cwd / "../examples/roles/role_detection").resolve(), + ) + result = run_ansible_lint( + Path("roles/role_detection/foo/defaults/main.yml"), + cwd=cwd, + env=env, + ) + assert result.returncode == RC.SUCCESS + + +def test_run_role_identified_prefix_missing(local_test_dir: Path) -> None: + """Test that role name is identified correctly, with prefix violations.""" + cwd = local_test_dir + + env = os.environ.copy() + env["ANSIBLE_ROLES_PATH"] = os.path.realpath( + (cwd / "../examples/roles/role_detection/base").resolve(), + ) + result = run_ansible_lint( + Path("roles/role_detection/base/bar/defaults/main.yml"), + cwd=cwd, + env=env, + ) + assert result.returncode == RC.VIOLATIONS_FOUND + assert ( + "Variables names from within roles should use bar_ as a prefix" in result.stdout + ) + assert ( + "Variables names from within roles should use bar_ as a prefix" in result.stdout + ) |