diff --git a/docs/installing.md b/docs/installing.md index 5f7aa5ed..f1120cee 100644 --- a/docs/installing.md +++ b/docs/installing.md @@ -123,15 +123,21 @@ $ tree -lla /home/ansible-dev/collections/ansible_collections/testns/testname │ └── runtime.yml ├── plugins │ ├── action +│ │ ├── sample_action.py │ │ └── __init__.py │ ├── cache │ │ └── __init__.py +│ ├── lookup +│ │ ├── sample_lookup.py +│ │ └── __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 @@ -139,8 +145,9 @@ $ tree -lla /home/ansible-dev/collections/ansible_collections/testns/testname │ │ └── __init__.py │ ├── sub_plugins │ │ └── __init__.py -│ └── test -│ └── __init__.py +│ ├── test +│ │ ├── sample_test.py +│ │ └── __init__.py ├── .pre-commit-config.yaml ├── .prettierignore ├── pyproject.toml @@ -381,6 +388,7 @@ $ ansible-creator add plugin | 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 diff --git a/src/ansible_creator/resources/collection_project/plugins/test/sample_test.py.j2 b/src/ansible_creator/resources/collection_project/plugins/test/sample_test.py.j2 index 4123f64f..73a20dda 100644 --- a/src/ansible_creator/resources/collection_project/plugins/test/sample_test.py.j2 +++ b/src/ansible_creator/resources/collection_project/plugins/test/sample_test.py.j2 @@ -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. @@ -62,4 +61,4 @@ class TestModule: Returns: dict: The test plugin functions. """ - return {"{{ test_name }}": _hello_world} + return {"{{ test_name }}": _sample_test} diff --git a/tests/fixtures/collection/testorg/testcol/plugins/test/sample_test.py b/tests/fixtures/collection/testorg/testcol/plugins/test/sample_test.py index 1b2d607d..9101f5d6 100644 --- a/tests/fixtures/collection/testorg/testcol/plugins/test/sample_test.py +++ b/tests/fixtures/collection/testorg/testcol/plugins/test/sample_test.py @@ -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. @@ -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} diff --git a/tests/units/test_init.py b/tests/units/test_init.py index aefec935..df8565f8 100644 --- a/tests/units/test_init.py +++ b/tests/units/test_init.py @@ -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=[])