summaryrefslogtreecommitdiffstats
path: root/test/test_cli_role_paths.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 06:24:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 06:24:58 +0000
commitba233a0cbad76b4783a03893e7bf4716fbc0f0ec (patch)
treead369728c1edbe3631c8150585659078ae5d7d0b /test/test_cli_role_paths.py
parentReleasing progress-linux version 6.17.2-3~progress7.99u1. (diff)
downloadansible-lint-ba233a0cbad76b4783a03893e7bf4716fbc0f0ec.tar.xz
ansible-lint-ba233a0cbad76b4783a03893e7bf4716fbc0f0ec.zip
Merging upstream version 24.6.1.
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.py44
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
+ )