-
Notifications
You must be signed in to change notification settings - Fork 28
Testing our collection
As testing framework, we have implemented:
- Unit test for modules
- Playbooks to test the roles and module's functionality.
The class TestQueueManager tests if the state of a queue manager has been changed after calling the queue_manager.py
module. It uses the module's attribute unit_test as a flag (unit_test: True
) to indicate that the module is being called in a unit test. Our tests checks if a queue manager has been:
- Created -
state: present
- Started -
state: running
- Deleted -
state: absent
Please note this does not test the performance of our collection.
Note: Exeption classes AnsibleExitJson
and AnsibleFailJson
should be set. See test_queue_manager.py
for reference.
def test_delete_qm(self):
set_module_args({
'qmname': 'qm1',
'state': 'absent',
'description': 'testing',
'unit_test': True
})
with self.assertRaises(AnsibleExitJson) as result:
queue_manager.main()
self.assertEquals(result.exception.args[0]['state'], 'absent')
These playbooks test the functionality and performance of the roles and the queue_manager module in ansible plays.
To run the test playbooks first:
- make sure you are in the right directory
$ cd tests/playbooks
- export the modules to your ansible library
$ export ANSIBLE_LIBRARY=<PATH-TO>/ansible_mq/ansible_collections/ibm/ibmmq/library
-
NOTE : change
<PATH-TO>
to your local directory path:
-
NOTE : change
- run all test playbooks with
main.py
Use the ansible attribute fail_when: False
when calling the module in the ansible playbook but do not use this on assert statements. This will allow the other tests to run along with the clean up, indicating the failed test.