---
- name: Target tests
  hosts: all
  tasks:
    - name: Run target tests
      block:
        - name: Call role to change target settings
          include_role:
            name: fedora.linux_system_roles.firewall
          vars:
            firewall:
              - set_default_zone: public
                permanent: true
              - target: DROP
                state: enabled
                permanent: true

        - name: Get target setting
          command: firewall-offline-cmd --info-zone=public
          changed_when: false
          register: __result

        - name: Verify target setting
          assert:
            that: __expected in __result.stdout_lines
          vars:
            __expected: "  target: DROP"

        - name: Call role to reset target settings
          include_role:
            name: fedora.linux_system_roles.firewall
          vars:
            firewall:
              target: DROP
              state: absent
              permanent: true

        - name: Get target setting
          command: firewall-offline-cmd --info-zone=public
          changed_when: false
          register: __result

        - name: Verify target setting was reset
          assert:
            that: __expected not in __result.stdout_lines
          vars:
            __expected: "  target: DROP"
      always:
        - name: Cleanup
          tags:
            - tests::cleanup
          include_role:
            name: fedora.linux_system_roles.firewall
          vars:
            firewall:
              - previous: replaced
