Skip to content

Commit

Permalink
Refactor package hold verification tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak committed Mar 27, 2024
1 parent 6309b43 commit e35a6e5
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions molecule/hold/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,31 @@
ansible.builtin.package_facts:

- name: Verify package versions
ansible.builtin.fail:
msg: "Expected installed version for package {{ _package }} to be {{ _version }}, found {{ _installed }}"
ansible.builtin.assert:
that:
- _package in packages
- _version == _installed
fail_msg: "Expected {{ _package }}={{ _version }}, found {{ _package }}={{ _installed }}"
success_msg: "Found {{ _package }}={{ _version }}"
vars:
_package: "{{ item.split('=') | first }}"
_version: "{{ item.split('=') | last }}"
_installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}"
loop: "{{ postgresql_package_list }}"
when:
- ansible_os_family == "Debian"
- _package not in packages or _version != _installed
when: ansible_os_family == "Debian"

- name: Verify package versions
ansible.builtin.fail:
msg: "Expected installed version for package {{ _package }} to be {{ _version }}, found {{ _installed }}"
ansible.builtin.assert:
that:
- _package in packages
- _version == _installed
fail_msg: "Expected {{ _package }}={{ _version }}, found {{ _package }}={{ _installed }}"
success_msg: "Found {{ _package }}={{ _version }}"
vars:
_prefix: "^{{ _package }}-"
_suffix: "-.*$"
_package: "{{ item.0 }}"
_version: "{{ item.1 | regex_replace(_prefix, '') | regex_replace(_suffix, '') }}"
_installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}"
loop: "{{ postgresql_package_list | zip(_postgresql_package_name) }}"
when:
- ansible_os_family == "RedHat"
- _package not in packages or _version != _installed
loop: "{{ _postgresql_package_name | zip(postgresql_package_list) }}"
when: ansible_os_family == "RedHat"

0 comments on commit e35a6e5

Please sign in to comment.