Skip to content

Updated the Installing.md docs and updated the sample_test.py.j2 file #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/installing.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,28 @@ $ tree -lla /home/ansible-dev/collections/ansible_collections/testns/testname
│ └── runtime.yml
├── plugins
│ ├── action
│ │ ├── sample_action.py
│ │ └── __init__.py
│ ├── cache
│ │ └── __init__.py
│ ├── filter
│ │ ├── hello_world.py
│ │ ├── sample_filter.py
│ │ └── __init__.py
│ ├── inventory
│ │ └── __init__.py
│ ├── modules
│ │ ├── sample_module.py
│ │ ├── sample_action.py
│ │ └── __init__.py
│ ├── module_utils
│ │ └── __init__.py
│ ├── plugin_utils
│ │ └── __init__.py
│ ├── sub_plugins
│ │ └── __init__.py
│ └── test
│ └── __init__.py
│ ├── test
│ │ ├── sample_test.py
│ │ └── __init__.py
├── .pre-commit-config.yaml
├── .prettierignore
├── pyproject.toml
Expand Down Expand Up @@ -381,6 +385,7 @@ $ ansible-creator add plugin <plugin-type> <plugin-name> <collection-path>
| filter | Add a filter plugin to an existing Ansible Collection. |
| lookup | Add a lookup plugin to an existing Ansible Collection. |
| module | Add a generic module to an existing Ansible Collection. |
| test | Add a test plugin to an existing Ansible Collection |

#### Example of adding a plugin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,23 @@ DOCUMENTATION = """
version_added: "1.0.0"
short_description: {{ description }}
description:
- This is a demo test plugin designed to return Hello message.
- This is a demo test plugin designed to return a bool.
options:
name:
description: Value specified here is appended to the Hello message.
type: str
type: bool
"""

EXAMPLES = """
# {{ test_name }} test example
{% raw %}
- name: Display a hello message
- name: Display a bool
ansible.builtin.debug:
msg: "{{ 50 {%- endraw %} | {{ test_name }} }}"
"""


def _hello_world(val: int) -> bool:
"""Returns Hello message.
def _sample_test(val: int) -> bool:
"""Returns a bool.

Args:
val: The value to test.
Expand All @@ -62,4 +61,4 @@ class TestModule:
Returns:
dict: The test plugin functions.
"""
return {"{{ test_name }}": _hello_world}
return {"{{ test_name }}": _sample_test}
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,23 @@
version_added: "1.0.0"
short_description: A custom test plugin for Ansible.
description:
- This is a demo test plugin designed to return Hello message.
- This is a demo test plugin designed to return a bool.
options:
name:
description: Value specified here is appended to the Hello message.
type: str
type: bool
"""

EXAMPLES = """
# sample_test test example

- name: Display a hello message
- name: Display a bool
ansible.builtin.debug:
msg: "{{ 50 | sample_test }}"
"""


def _hello_world(val: int) -> bool:
"""Returns Hello message.
def _sample_test(val: int) -> bool:
"""Returns a bool.

Args:
val: The value to test.
Expand All @@ -57,4 +56,4 @@ def tests(self) -> dict[str, Callable[[int], bool]]:
Returns:
dict: The test plugin functions.
"""
return {"sample_test": _hello_world}
return {"sample_test": _sample_test}
8 changes: 0 additions & 8 deletions tests/units/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,6 @@ def mock_unique_name_in_devfile(init: Init) -> str:
# check stdout
assert re.search(r"Note: collection project created", result) is not None

# Fix the directory structure to match the expected fixture
# Rename 'integration_' to 'integration_hello_world'
generated_molecule_dir = tmp_path / "testorg" / "testcol" / "extensions" / "molecule"
if (generated_molecule_dir / "integration_").exists():
(generated_molecule_dir / "integration_").rename(
generated_molecule_dir / "integration_hello_world"
)

# recursively assert files created
cmp = dircmp(str(tmp_path), str(FIXTURES_DIR / "collection"), ignore=[".DS_Store"])
diff = has_differences(dcmp=cmp, errors=[])
Expand Down