Skip to content

Commit

Permalink
Add plugin loader test (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ирина Розет committed Oct 14, 2024
1 parent 33799e2 commit 21ce1eb
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,44 @@ def test_install_collection_from_disk(
runtime.clean()


@pytest.mark.parametrize(
("path", "expected_plugins"),
(
pytest.param(
"test/collections/acme.goodies",
[
"ansible.posix.patch", # from tests/requirements.yml
"ansible.utils.validate", # from galaxy.yml
"community.crypto.acme_account", # from galaxy.yml as a git dependency
],
id="modules",
),
),
)
def test_load_plugins(
path: str,
expected_plugins: list[str],
) -> None:
"""Tests ability to load plugin from a collection installed by requirement."""
with cwd(Path(path)):
from ansible.plugins.loader import module_loader
from ansible_compat.prerun import get_cache_dir
rmtree(get_cache_dir(Path.cwd()), ignore_errors=True)
runtime = Runtime(isolated=True, require_module=True)
runtime.prepare_environment(install_local=True)
for plugin_name in expected_plugins:
loaded_module = module_loader.find_plugin_with_context(
plugin_name,
ignore_deprecated=True,
check_aliases=True,
)
assert (
loaded_module.resolved_fqcn is not None
), f"Unable to load module {plugin_name}"

runtime.clean()


def test_install_collection_from_disk_fail() -> None:
"""Tests that we fail to install a broken collection."""
with cwd(Path("test/collections/acme.broken")):
Expand Down

0 comments on commit 21ce1eb

Please sign in to comment.