Kevin Veen-Birkenbach 29f50da226
Add custom Ansible filter plugin get_category_entries
This commit introduces a new Ansible filter plugin named
'get_category_entries', which returns all role names under the
roles/ directory that start with a given prefix.

Additionally, unit tests (unittest framework) have been added under
tests/unit/filterplugins/ to ensure correct behavior, including:

- Returns empty list when roles/ directory is missing
- Correctly filters and sorts by prefix
- Ignores non-directory entries
- Supports custom roles_path argument
- Returns all roles when prefix is empty

Reference: https://chatgpt.com/share/68a2f1ab-1fe8-800f-b22a-28c1c95802c2
2025-08-18 11:27:26 +02:00
..
2025-07-21 15:09:38 +02:00
2025-08-07 11:31:06 +02:00
2025-07-12 18:41:13 +02:00
2025-07-16 08:25:16 +02:00

Unit Tests

This directory contains unit tests for various custom components in the project, such as the custom lookup plugin docker_cards used in the web-app-port-ui role.

Overview

The unit tests are written using Pythons built-in unittest framework. They are designed to verify that your custom logic works as expected—such as extracting metadata from role files—without needing to run the entire playbook.

Running the Tests

You can run the tests using one of the following methods:

  1. Using Unittest Discovery:

    From the project's root directory, run:

    python -m unittest discover -s tests/unit
    

    This command will discover and execute all test files within the tests/unit directory.

  2. Running a Specific Test File:

    If you want to run only the Docker cards test, execute:

    python tests/unit/test_docker_cards.py
    

How It Works

  • Setup:
    The test script creates a temporary directory to simulate your roles folder. It then creates a sample role (web-app-port-ui) with a README.md file (containing a header for the title) and a meta/main.yml file (with the required metadata).

  • Execution:
    Dummy variable values for domains and applications are provided (these are the variables the lookup plugin expects). The lookup plugin is then run, which processes the sample role and returns the card information.

  • Verification:
    The test uses assertions to ensure that the output contains the expected title, description, icon information, constructed URL, and the correct iframe flag.

  • Cleanup:
    After the test completes, the temporary directory is removed, ensuring that no test artifacts remain.

Requirements

  • Python 3.6 or newer is recommended.
  • All necessary dependencies for your project should be installed.

These tests help ensure that your custom code is reliable and behaves as expected, and they can be easily integrated into a Continuous Integration (CI) pipeline.

Happy testing!