Skip to content

Commit

Permalink
add unit tests for discoveryrule
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Lathrop committed May 7, 2024
1 parent 9b92deb commit b054f20
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- setup_zabbix
29 changes: 29 additions & 0 deletions tests/integration/targets/test_zabbix_discoveryrule/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: test - do not run tests for Zabbix < 6.4
meta: end_play
when: zabbix_version is version('6.4', '<')

- block:
# setup stuff
- include_tasks: zabbix_setup.yml

# zabbix_item module tests
- include_tasks: zabbix_tests.yml

# tear down stuff set up earlier
- include_tasks: zabbix_teardown.yml

always:
- name: "cleanup discoveryrule if tests failed"
community.zabbix.zabbix_discoveryrule:
host_name: ExampleHost
name: ExampleRule
state: absent
ignore_errors: true

- name: "cleanup discoveryrule if tests failed"
community.zabbix.zabbix_discoveryrule:
template_name: ExampleTemplate
name: ExampleRule
state: absent
ignore_errors: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---

- name: Create test template
community.zabbix.zabbix_template:
template_name: ExampleTemplate
template_groups:
- Templates

- name: Create test host
community.zabbix.zabbix_host:
host_name: ExampleHost
host_groups:
- Linux servers
- Zabbix servers
link_templates:
- ExampleTemplate
status: enabled
state: present
interfaces:
- type: 1
main: 1
useip: 1
ip: 10.1.1.1
dns: ""
port: "10050"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- name: remove test host
community.zabbix.zabbix_host:
host_name: ExampleHost
state: absent

- name: remove test template
community.zabbix.zabbix_template:
template_name: ExampleTemplate
state: absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
---

- name: test - create new Zabbix discoveryrule on host with many options set
community.zabbix.zabbix_discoveryrule:
name: TestRule
host_name: ExampleHost
params:
type: zabbix_agent_active
key: 'vfs.fs.discovery'
interval: 1m
enabled: True
tags:
- tag: tag
value: value
state: present
register: zbxhostrule_new

- name: assert that rule was created
ansible.builtin.assert:
that: zbxhostrule_new is changed

- name: test - create same Zabbix discoveryrule once again
community.zabbix.zabbix_discoveryrule:
name: TestRule
host_name: ExampleHost
params:
type: zabbix_agent_active
key: 'vfs.fs.discovery'
interval: 1m
enabled: True
tags:
- tag: tag
value: value
state: present
register: zbxhostrule_existing

- name: assert that nothing has been changed
ansible.builtin.assert:
that: not zbxhostrule_existing is changed

- name: test - update existing zabbix discoveryrule
community.zabbix.zabbix_discoveryrule:
name: TestRule
host_name: ExampleHost
params:
interval: 2m
state: present
register: zbxhostrule_changed

- name: expect to succeed and that things changed
ansible.builtin.assert:
that: zbxhostrule_changed is changed

- name: test - attempt to delete previously created zabbix discoveryrule
community.zabbix.zabbix_discoveryrule:
name: TestRule
host_name: ExampleHost
state: absent
register: zbxhostrule_existing_delete

- name: assert that trigger was deleted
ansible.builtin.assert:
that: zbxhostrule_existing_delete is changed

- name: test - attempt to delete non-existing zabbix discoveryrule
community.zabbix.zabbix_discoveryrule:
name: TestRule
host_name: ExampleHost
state: absent
register: zbxhostrule_missing_delete

- name: assert that nothing has been changed
ansible.builtin.assert:
that: not zbxhostrule_missing_delete is changed

- name: test - create new Zabbix discoveryrule on template with many options set
community.zabbix.zabbix_discoveryrule:
name: TestRule
template_name: ExampleTemplate
params:
type: zabbix_agent_active
key: 'vfs.fs.discovery'
interval: 1m
enabled: True
tags:
- tag: tag
value: value
state: present
register: zbxtemprule_new

- name: assert that rule was created
ansible.builtin.assert:
that: zbxtemprule_new is changed

- name: test - create same Zabbix discoveryrule once again
community.zabbix.zabbix_discoveryrule:
name: TestRule
template_name: ExampleTemplate
params:
type: zabbix_agent_active
key: 'vfs.fs.discovery'
interval: 1m
enabled: True
tags:
- tag: tag
value: value
state: present
register: zbxtemprule_existing

- name: assert that nothing has been changed
ansible.builtin.assert:
that: not zbxtemprule_existing is changed

- name: test - update existing zabbix discoveryrule
community.zabbix.zabbix_discoveryrule:
name: TestRule
template_name: ExampleTemplate
params:
interval: 2m
state: present
register: zbxtemprule_changed

- name: expect to succeed and that things changed
ansible.builtin.assert:
that: zbxtemprule_changed is changed

- name: test - attempt to delete previously created zabbix discoveryrule
community.zabbix.zabbix_discoveryrule:
name: TestRule
template_name: ExampleTemplate
state: absent
register: zbxtemprule_existing_delete

- name: assert that trigger was deleted
ansible.builtin.assert:
that: zbxtemprule_existing_delete is changed

- name: test - attempt to delete non-existing zabbix discoveryrule
community.zabbix.zabbix_discoveryrule:
name: TestRule
template_name: ExampleTemplate
state: absent
register: zbxtemprule_missing_delete

- name: assert that nothing has been changed
ansible.builtin.assert:
that: not zbxtemprule_missing_delete is changed

0 comments on commit b054f20

Please sign in to comment.