Skip to content

Commit

Permalink
Improve zabbix_connector test coverage and fix item_value_types bug
Browse files Browse the repository at this point in the history
  • Loading branch information
loricvdt committed Dec 31, 2024
1 parent 9530319 commit 85f4bf6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
12 changes: 6 additions & 6 deletions plugins/modules/zabbix_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ class Connector(ZabbixBase):
}

VALUE_TYPES = {
"numeric_float": "1",
"character": "2",
"log": "4",
"numeric_unsigned": "8",
"text": "10",
"binary": "20",
"numeric_float": 1,
"character": 2,
"log": 4,
"numeric_unsigned": 8,
"text": 10,
"binary": 20,
}

AUTH_TYPES = {
Expand Down
47 changes: 46 additions & 1 deletion tests/integration/targets/test_zabbix_connector/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,58 @@
value: hidden
register: connector_auth_tags_update

- name: assert that auth has changed
- name: assert that auth has not changed
ansible.builtin.assert:
that: not connector_auth_tags_update is changed

- name: test - set item value type (version >= 7.0)
community.zabbix.zabbix_connector:
name: ExampleConnector1
url: https://127.0.0.1/api/zabbix_stream
data_type: item_values
item_value_types: "{{ item }}"
loop:
- ["numeric_float"]
- ["numeric_float", "numeric_unsigned", "character", "text"]
- ["all+bin"]
- ["all"]
when: zabbix_version is version('7.0', '>=')
register: connector_value_type

- name: assert that all item value type updates lead to changed
ansible.builtin.assert:
that:
- connector_value_type.results | map(attribute='changed') is all

- name: test - set non existent item value type (version >= 7.0)
community.zabbix.zabbix_connector:
name: ExampleConnector1
url: https://127.0.0.1/api/zabbix_stream
data_type: item_values
item_value_types:
- not_a_real_value_type
when: zabbix_version is version('7.0', '>=')
register: connector_wrong_value_type
ignore_errors: true

- name: assert that the module failed
ansible.builtin.assert:
that: connector_wrong_value_type is failed and "is not a known value type" in connector_wrong_value_type.msg

always:
- name: Cleanup connector
community.zabbix.zabbix_connector:
name: ExampleConnector1
state: absent
ignore_errors: true

- name: test - cleanup connector (again)
community.zabbix.zabbix_connector:
name: ExampleConnector1
state: absent
ignore_errors: true
register: connector_delete

- name: assert that nothing has changed
ansible.builtin.assert:
that: not connector_delete is changed or connector_delete is failed

0 comments on commit 85f4bf6

Please sign in to comment.