diff --git a/src/ansible_compat/runtime.py b/src/ansible_compat/runtime.py index 0ca4e8c9..2e14bb11 100644 --- a/src/ansible_compat/runtime.py +++ b/src/ansible_compat/runtime.py @@ -302,6 +302,7 @@ def prepare_environment( retry: bool = False, install_local: bool = False, offline: bool = False, + role_name_check: int = 0, ) -> None: """Make dependencies available if needed.""" if required_collections is None: @@ -342,7 +343,9 @@ def prepare_environment( self.install_collection_from_disk("../..", destination=destination) else: # no collection, try to recognize and install a standalone role - self._install_galaxy_role(self.project_dir, ignore_errors=True) + self._install_galaxy_role( + self.project_dir, role_name_check=role_name_check, ignore_errors=True + ) def require_collection( # noqa: C901 self, diff --git a/test/test_runtime.py b/test/test_runtime.py index d19b76a5..cad9232f 100644 --- a/test/test_runtime.py +++ b/test/test_runtime.py @@ -511,6 +511,36 @@ def test_install_galaxy_role_bad_namespace(runtime_tmp: Runtime) -> None: runtime_tmp._install_galaxy_role(runtime_tmp.project_dir, role_name_check=1) +@pytest.mark.parametrize( + "galaxy_info", + ( + """galaxy_info: + role_name: foo-bar + namespace: acme +""", + """galaxy_info: + role_name: foo-bar +""", + ), + ids=("bad-name", "bad-name-without-namespace"), +) +def test_install_galaxy_role_name_role_name_check_equals_to_1( + runtime_tmp: Runtime, + galaxy_info: str, + caplog: pytest.LogCaptureFixture, +) -> None: + """Check install role with bad role name in galaxy info.""" + caplog.set_level(logging.WARN) + pathlib.Path(f"{runtime_tmp.project_dir}/meta").mkdir() + pathlib.Path(f"{runtime_tmp.project_dir}/meta/main.yml").write_text( + galaxy_info, + encoding="utf-8", + ) + + runtime_tmp._install_galaxy_role(runtime_tmp.project_dir, role_name_check=1) + assert "Computed fully qualified role name of " in caplog.text + + def test_install_galaxy_role_no_checks(runtime_tmp: Runtime) -> None: """Check install role with bad namespace in galaxy info.""" runtime_tmp.prepare_environment() diff --git a/tox.ini b/tox.ini index 12b16495..9e5f2761 100644 --- a/tox.ini +++ b/tox.ini @@ -52,7 +52,7 @@ setenv = PIP_DISABLE_PIP_VERSION_CHECK = 1 PIP_CONSTRAINT = {toxinidir}/requirements.txt PRE_COMMIT_COLOR = always - PYTEST_REQPASS = 76 + PYTEST_REQPASS = 78 FORCE_COLOR = 1 allowlist_externals = ansible