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 c1c81ba
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,44 @@ def test_install_collection_from_disk(
assert (
collection_name in runtime.collections
), f"{collection_name} not found in {runtime.collections.keys()}"

runtime.clean()


@pytest.mark.parametrize(
("path", "scenario", "expected_plugins"),
(
pytest.param(
"test/collections/acme.goodies",
"default",
[
"ansible.posix.patch", # from tests/requirements.yml
"ansible.utils.validate", # from galaxy.yml
"community.crypto.acme_account", # from galaxy.yml as a git dependency
],
),
),
)
def test_load_plugins(
path: str,
scenario: 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} - 1"

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 c1c81ba

Please sign in to comment.