Skip to content

Commit

Permalink
Expose role_name_check in prepare_environment (#147)
Browse files Browse the repository at this point in the history
Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
Co-authored-by: Sorin Sbarnea <sorin.sbarnea@gmail.com>
  • Loading branch information
3 people authored May 23, 2022
1 parent 9ed200b commit 1d53bc9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/ansible_compat/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions test/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1d53bc9

Please sign in to comment.