---
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_facts sanity test"

- name: "nxos_facts gather hardware facts"
  nxos_facts:
    gather_subset: hardware
    provider: "{{ connection }}"
  register: result

- assert:
    that:
      # _facts modules should never report a change
      - "result.changed == false"

      # Correct subsets are present
      - "'hardware' in result.ansible_facts.ansible_net_gather_subset"

      # Other facts are not present
      - "'config' not in result.ansible_facts.ansible_net_gather_subset"
      - "'interfaces' not in result.ansible_facts.ansible_net_gather_subset"

      # Items from those subsets are present
      - "result.ansible_facts.ansible_net_filesystems is defined"

      # Check that these facts not only are present, but are valid (positive integers)
      - "result.ansible_facts.ansible_net_memfree_mb > 1"
      - "result.ansible_facts.ansible_net_memtotal_mb > 1"

- name: "nxos_facts gather config facts"
  nxos_facts:
    gather_subset: config
    provider: "{{ connection }}"
  register: result

- assert:
    that:
      # _facts modules should never report a change
      - "result.changed == false"

      # Correct subsets are present
      - "'config' in result.ansible_facts.ansible_net_gather_subset"

      # Other facts are not present
      - "'hardware' not in result.ansible_facts.ansible_net_gather_subset"
      - "'interfaces' not in result.ansible_facts.ansible_net_gather_subset"

      # Items from those subsets are present
      - "result.ansible_facts.ansible_net_config is defined"

- name: "nxos_facts gather config and hardware facts"
  nxos_facts:
    gather_subset:
      - hardware
      - config
    provider: "{{ connection }}"
  register: result

- assert:
    that:
      # _facts modules should never report a change
      - "result.changed == false"

      # Correct subsets are present
      - "'hardware' in result.ansible_facts.ansible_net_gather_subset"
      - "'config' in result.ansible_facts.ansible_net_gather_subset"

      # Other facts are not present
      - "'interfaces' not in result.ansible_facts.ansible_net_gather_subset"

      # Items from those subsets are present
      - "result.ansible_facts.ansible_net_filesystems is defined"
      - "result.ansible_facts.ansible_net_config is defined"

      # Check that these facts not only are present, but are valid (positive integers)
      - "result.ansible_facts.ansible_net_memfree_mb > 1"
      - "result.ansible_facts.ansible_net_memtotal_mb > 1"

- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_facts sanity test"
