Scope of a single scenario - should I call my role multiple times in one scenario #4012
-
Hi, I have a number of input variables for a role and perform some basic input validation on them before executing the main tasks in the role. See below.
I see two approaches to testing this input validation.
Number 1 creates a lot of overhead even if I was to create share some of the molecule step playbooks/resources between scenarios. Number 2 is the opposite end of the spectrum where a number of similar "scenarios" are bundled together. Any thoughts or recommendations on how to proceed or is there some other alternative? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
That's what role argument validation is for. See: https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse_roles.html#specification-format This is much more powerful than just asserting the right role variables. It also gives you documentation. |
Beta Was this translation helpful? Give feedback.
-
IMHO, I would do 1 scenario for each check (set of vars). The reason is, it is easier to isolate, test, and see and recreate a failure. If you are using the pytest-ansible pluign, each scenario will show as an individual pytest test so when running in your CI it's easier to specific exactly which one failed. In the end, having the tests is better than not having them, so which ever why you choose to go, everything will be better. :) |
Beta Was this translation helpful? Give feedback.
IMHO, I would do 1 scenario for each check (set of vars). The reason is, it is easier to isolate, test, and see and recreate a failure. If you are using the pytest-ansible pluign, each scenario will show as an individual pytest test so when running in your CI it's easier to specific exactly which one failed.
In the end, having the tests is better than not having them, so which ever why you choose to go, everything will be better. :)