# SPDX-License-Identifier: BSD-3-Clause
---
- name: Run test
  block:
    - name: "TEST: {{ lsr_description }}"
      debug:
        msg: "########## {{ lsr_description }} ##########"

    - name: Show item
      debug:
        var: "{{ item }}"
      loop:
        - lsr_description
        - lsr_setup
        - lsr_test
        - lsr_assert
        - lsr_assert_when
        - lsr_fail_debug
        - lsr_cleanup

    - name: Include the task 'show_interfaces.yml'
      include_tasks: tasks/show_interfaces.yml

    - name: Setup
      include_tasks: "{{ item }}"
      loop: "{{ lsr_setup }}"
      tags:
        - "tests::setup"

    - name: Test
      include_tasks: "{{ item }}"
      loop: "{{ lsr_test }}"
      tags:
        - "tests::test"

    - name: Asserts
      include_tasks: "{{ item }}"
      loop: "{{ lsr_assert }}"
      tags:
        - "tests::assert"

    - name: Conditional asserts
      include_tasks: "{{ item['what'] }}"
      when: item['condition']
      loop: "{{ lsr_assert_when | default([]) }}"

    - name: "Success in test '{{ lsr_description }}'"
      debug:
        msg: "+++++ Success in test '{{ lsr_description }}' +++++"

  rescue:
    - name: "Failure in test '{{ lsr_description }}'"
      debug:
        msg: "!!!!! Failure in test '{{ lsr_description }}' !!!!!"

    - name: Show item that failed
      debug:
        var: "{{ item }}"
      loop: "{{ lsr_fail_debug | default([]) }}"

    - name: Issue failed message
      fail:
        msg: "!!!!! Failure in test '{{ lsr_description }}' !!!!!"

  always:
    - name: Cleanup
      include_tasks: "{{ item }}"
      loop: "{{ lsr_cleanup }}"
      tags:
        - "tests::cleanup"
...
