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 3930431 commit 5ff1bb7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
env:
FORCE_COLOR: 1
PYTEST_REQPASS: 108
PYTEST_REQPASS: 109
steps:
- uses: actions/checkout@v4
with:
Expand Down
38 changes: 38 additions & 0 deletions test/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import pytest
from packaging.version import Version

from ansible.plugins.loader import module_loader

from ansible_compat.constants import INVALID_PREREQUISITES_RC
from ansible_compat.errors import (
AnsibleCommandError,
Expand Down Expand Up @@ -742,6 +744,42 @@ 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
"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_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 5ff1bb7

Please sign in to comment.