From a731b5cd4b13e479007e4978964fb519db59485e Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 4 Dec 2025 10:36:15 +0100 Subject: [PATCH] Optimized test and added more output --- .../test_role_include_import_roles_exist.py | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_role_include_import_roles_exist.py b/tests/integration/test_role_include_import_roles_exist.py index 1008e3a0..29bc973c 100644 --- a/tests/integration/test_role_include_import_roles_exist.py +++ b/tests/integration/test_role_include_import_roles_exist.py @@ -57,17 +57,37 @@ class TestIncludeImportRoleExistence(unittest.TestCase): self.fail(f"Failed to parse YAML in {file_path}") for doc in docs: + # Skip empty YAML documents (e.g. only "---") + if doc is None: + continue + for role_name in self._collect_includes(doc): + + # NEW: Validate that role_name is a proper string + if not isinstance(role_name, str) or not role_name.strip(): + self.fail( + "Invalid include_role/import_role name detected.\n" + f" • File: {file_path}\n" + f" • Extracted name value: {repr(role_name)}\n" + "The 'name:' field must contain a non-empty string.\n" + "Example:\n" + " include_role:\n" + " name: my-role-name\n" + ) + # Convert Jinja2 templates and wildcards to glob patterns pattern = re.sub(r"\{\{.*?\}\}", '*', role_name) glob_path = os.path.join(self.roles_dir, pattern) - # Check for matching role directories + matches = [p for p in glob.glob(glob_path) if os.path.isdir(p)] if not matches: missing.append((file_path, role_name)) if missing: - messages = [f"File '{fp}' references missing role '{rn}'" for fp, rn in missing] + messages = [ + f"File '{fp}' references missing role '{rn}'" + for fp, rn in missing + ] self.fail("\n".join(messages)) if __name__ == '__main__':