---
# Test playbook for the firewalld module - icmp block inversion operations
# (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- name: Icmp block inversion enabled when icmp block inversion is truthy and state is enabled
  block:
    - name: Testing enable icmp block inversion
      ansible.posix.firewalld:
        zone: trusted
        icmp_block_inversion: true
        permanent: true
        state: enabled
      register: result

    - name: Assert icmp block inversion is enabled
      ansible.builtin.assert:
        that:
          - result is changed

    - name: Testing enable icmp block inversion (verify not changed)
      ansible.posix.firewalld:
        zone: trusted
        icmp_block_inversion: true
        permanent: true
        state: enabled
      register: result

    - name: Assert icmp block inversion is enabled (verify not changed)
      ansible.builtin.assert:
        that:
          - result is not changed

- name: Icmp block inversion disabled when icmp block inversion is falsy and state is enabled
  block:
    - name: Testing disable icmp block inversion
      ansible.posix.firewalld:
        zone: trusted
        icmp_block_inversion: false
        permanent: true
        state: enabled
      register: result

    - name: Assert icmp block inversion is disabled
      ansible.builtin.assert:
        that:
          - result is changed

    - name: Testing disable icmp block inversion (verify not changed)
      ansible.posix.firewalld:
        zone: trusted
        icmp_block_inversion: false
        permanent: true
        state: enabled
      register: result

    - name: Assert icmp block inversion is disabled (verify not changed)
      ansible.builtin.assert:
        that:
          - result is not changed

- name: Icmp block inversion enabled when icmp block inversion is falsy and state is disabled
  block:
    - name: Testing enable icmp block inversion
      ansible.posix.firewalld:
        zone: trusted
        icmp_block_inversion: false
        permanent: true
        state: disabled
      register: result

    - name: Assert icmp block inversion is enabled
      ansible.builtin.assert:
        that:
          - result is changed

    - name: Testing enable icmp block inversion (verify not changed)
      ansible.posix.firewalld:
        zone: trusted
        icmp_block_inversion: false
        permanent: true
        state: disabled
      register: result

    - name: Assert icmp block inversion is enabled (verify not changed)
      ansible.builtin.assert:
        that:
          - result is not changed

- name: Icmp block inversion disabled when icmp block inversion is truthy and state is disabled
  block:
    - name: Testing disable icmp block inversion
      ansible.posix.firewalld:
        zone: trusted
        icmp_block_inversion: true
        permanent: true
        state: disabled
      register: result

    - name: Assert icmp block inversion is disabled
      ansible.builtin.assert:
        that:
          - result is changed

    - name: Testing disable icmp block inversion (verify not changed)
      ansible.posix.firewalld:
        zone: trusted
        icmp_block_inversion: true
        permanent: true
        state: disabled
      register: result

    - name: Assert icmp block inversion is disabled (verify not changed)
      ansible.builtin.assert:
        that:
          - result is not changed
