- name: Test podman_logout
  block:

    - name: Print podman version
      command: podman version

    - name: Logout from docker if it exists
      command: docker logout
      ignore_errors: true

    - name: Log out with invalid executable
      containers.podman.podman_logout:
        executable: podman_invalid
      register: invalid_executable
      ignore_errors: true

    - name: Check invalid executable results
      assert:
        that:
          - invalid_executable is failed

    - name: Log out of non-existing registry
      containers.podman.podman_logout:
        executable: "{{ test_executable | default('podman') }}"
      register: non_existing_registry
      ignore_errors: true

    - name: Check results
      assert:
        that:
          - "'changed' in non_existing_registry"
          - "non_existing_registry.changed == False"

    - name: Log out with invalid authfile
      containers.podman.podman_logout:
        executable: "{{ test_executable | default('podman') }}"
        authfile: authfile_invalid.json
      register: invalid_authfile
      ignore_errors: true

    - name: Check invalid authfile results
      assert:
        that:
          - invalid_authfile is failed

    - name: Log out of all registries
      containers.podman.podman_logout:
        executable: "{{ test_executable | default('podman') }}"
        all: true
      register: all_registries

    - name: Check results
      assert:
        that:
          - "'changed' in all_registries"
          - "all_registries.changed == True"
