summaryrefslogtreecommitdiffstats
path: root/test/test_cli_role_paths.py
diff options
context:
space:
mode:
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
+ )