---
- name: Test role with default options
  hosts: all
  gather_facts: false
  roles:
    - linux-system-roles.cockpit

  tasks:
    - name: Tests
      block:
        - name: Test - socket is active  # noqa command-instead-of-module
          command: systemctl is-active {{ __cockpit_daemon }}
          changed_when: false

        - name: Test - socket is enabled  # noqa command-instead-of-module
          command: systemctl is-enabled {{ __cockpit_daemon }}
          changed_when: false

        - name: Test - cockpit works with TLS
          get_url:
            dest: /run/out
            url: https://localhost:9090
            validate_certs: false
            mode: "0600"

        - name: Test - HTTP response is something sensible
          command: grep 'id="login-user-input"' /run/out
          changed_when: false

        - name: Test - clean up output file
          file:
            path: /run/out
            state: absent

        - name: Test - no configuration file
          stat:
            path: /etc/cockpit/cockpit.conf
          register: result
          failed_when: result.stat.exists

        - name: Test - no port configuration file
          stat:
            path: /etc/systemd/system/cockpit.socket.d
          register: result
          failed_when: result.stat.exists

      always:
        - name: Cleanup
          include_tasks: tasks/cleanup.yml
