- name: Test podman_image_info
  block:

    - name: Get info on images when no images
      containers.podman.podman_image_info:
        executable: "{{ test_executable | default('podman') }}"
      register: info_0

    - name: Check results for no images
      assert:
        that:
          - info_0.images | length == 0

    - name: Pull image
      command: podman pull quay.io/coreos/etcd:v3.5.19

    - name: Get info on all images
      containers.podman.podman_image_info:
        executable: "{{ test_executable | default('podman') }}"
      register: all_image_result

    - name: Pull another image
      command: podman pull quay.io/coreos/dnsmasq

    - name: Get info on specific image
      containers.podman.podman_image_info:
        executable: "{{ test_executable | default('podman') }}"
        name: quay.io/coreos/dnsmasq
      register: named_image_result

    - name: Check results
      assert:
        that:
          - all_image_result.images | length > 0
          - named_image_result.images | length == 1
          - "'quay.io/coreos/dnsmasq' in named_image_result.images[0]['RepoTags'][0]"

    - name: Get info on single image that does not exist
      containers.podman.podman_image_info:
        executable: "{{ test_executable | default('podman') }}"
        name: nope
      register: single_nonexistent

    - name: Get info on multiple images that do not exist
      containers.podman.podman_image_info:
        executable: "{{ test_executable | default('podman') }}"
        name:
          - nope
          - reallynope
      register: multiple_nonexistent

    - name: Get info with one image that does not exist
      containers.podman.podman_image_info:
        executable: "{{ test_executable | default('podman') }}"
        name:
          - quay.io/coreos/dnsmasq
          - nope
          - quay.io/coreos/etcd:v3.5.19
      register: mixed_nonexistent

    - name: Ensure image info was returned when non-existent image info was requisted
      assert:
        that:
          - single_nonexistent.images | length == 0
          - multiple_nonexistent.images | length == 0
          - mixed_nonexistent.images | length == 2

  always:
    - name: Remove images
      containers.podman.podman_image:
        executable: "{{ test_executable | default('podman') }}"
        name: "{{ item }}"
        state: absent
      loop:
        - quay.io/coreos/etcd:v3.5.19
        - quay.io/coreos/dnsmasq
