---
- name: Setup xml and expected json
  ansible.builtin.set_fact:
    data: '
      <netconf-state xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"><schemas><schema/></schemas></netconf-state>
      '
    output:
      {
        "netconf-state":
          {
            "@xmlns": "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring",
            "schemas": { "schema": null },
          },
      }

- name: Debug
  ansible.builtin.debug:
    msg: "{{ data | ansible.utils.from_xml() }}"

- name: Integration tests with and without default engine as xmltodict and
  ansible.builtin.assert:
    that: "{{ output == item.test }}"
  loop:
    - test: "{{ data | ansible.utils.from_xml() }}"
    - test: "{{ data | ansible.utils.from_xml('xmltodict') }}"

- name: Setup invalid xml as input to ansible.utils.from_xml.
  ansible.builtin.set_fact:
    data: '<netconf-state xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">'

- name: Validate input xml
  ansible.builtin.set_fact:
    _result: "{{ data | ansible.utils.from_xml() }}"
  ignore_errors: true
  register: result

- name: Assert
  ansible.builtin.assert:
    that: "{{ msg in result.msg }}"
  vars:
    msg: "Error when using plugin 'from_xml': Input Xml is not valid"
