Skip to content
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

Refactor: Convert build_npm Role to Use Molecule for Testing #245

Open
kayiwa opened this issue Nov 8, 2024 · 1 comment
Open

Refactor: Convert build_npm Role to Use Molecule for Testing #245

kayiwa opened this issue Nov 8, 2024 · 1 comment
Assignees
Labels
🚧 maintenance Upkeep tasks and fixes

Comments

@kayiwa
Copy link
Collaborator

kayiwa commented Nov 8, 2024

This issue aims to improve the reliability and maintainability of the build_npm role by integrating Molecule for testing. Molecule provides a framework for creating and running automated tests for Ansible roles, ensuring they function as expected and remain compatible across different environments.

Tasks:

  1. Install Molecule:

    • If not already installed, install Molecule on the development machine: pip install molecule
    • This can also be in the Pipfile. (Look at the README for how python packages are managed) (add new molecule on requirements.txt (?))
  2. Initialize Molecule in the Role:

    • Navigate to the role directory: cd roles/build_dependencies]
    • Possible to borrow and example role like PUL
    • Initialize Molecule: molecule init
    • Choose the ansible verifier based on the role's requirements.
  3. Create molecule.yml:

    • Configure the testing environment in molecule.yml. This includes:
      • Selecting a base image.
      • Specifying provisioner options (Ansible version, inventory).
      • Configuring verifiers (test frameworks like Ansible, Testinfra).
      • Setup Github CI/CD
  4. Write Tests:

    • Create tests in the verify.yml file (or using other testing frameworks) to validate the role's functionality.
    • Use assertions to check if resources are correctly configured, files exist, services are running, and commands produce the expected output.
  5. Run Molecule Tests:

    • Execute molecule test to run the tests.
    • Analyze the test results and fix any failures or errors in the role.
  6. Integrate with CI/CD:

    • If applicable, integrate Molecule tests into the CI/CD pipeline to ensure that changes to the role do not break existing functionality.

Example molecule.yml (Docker):

---
dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: instance
    image: ubuntu:latest
provisioner:
  name: ansible
  playbooks:
    converge: ../playbook.yml
verifier:
  name: ansible

Benefits:

Improved Reliability: Catch errors and regressions early through automated testing.
Increased Maintainability: Ensure the role remains functional across different environments and Ansible versions.
Simplified Development: Develop and test the role in an isolated environment.
Enhanced Documentation: Molecule tests serve as executable documentation of the role's intended behavior.

Additional Notes:

  • Choose the right driver: Select the Molecule driver (Docker, Vagrant, Podman, etc.) that best suits the role's requirements and testing environment.
  • Write comprehensive tests: Cover different aspects of the role's functionality with a variety of test cases.
  • Idempotency: Ensure that the role is idempotent, meaning it can be run multiple times without causing unintended changes.
  • Integration with CI/CD: Incorporate Molecule tests into your CI/CD pipeline to automate testing and prevent regressions.
  • Documentation: Update the role's README file with instructions on how to run the Molecule tests.
@kayiwa kayiwa added the 🚧 maintenance Upkeep tasks and fixes label Nov 8, 2024
@kayiwa kayiwa changed the title Refactor: Convert build_dependencies Role to Use Molecule for Testing Refactor: Convert build_npm Role to Use Molecule for Testing Nov 11, 2024
@kayiwa
Copy link
Collaborator Author

kayiwa commented Nov 11, 2024

related to #165

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚧 maintenance Upkeep tasks and fixes
Projects
None yet
Development

No branches or pull requests

2 participants