---
- hosts: pfservers
  name: Run unit tests
  become: True

  vars:
    test_suites:
      # configurator is necessary to have Fingerbank configured
      - configurator
      - unit_tests/configure_smoke_db.yml
      - unit_tests/golang_tests.yml
      - unit_tests/perl_tests.yml
      - unit_tests/addons_functions_tests.yml
      - pfcron
      - backup_db_and_restore
      - backup_db_and_restore/teardown

  tasks:
    # only to debug what is injected in Ansible environment
    # - name: Display ansible_env
    #   command: printenv
    #   environment: '{{ inventory__group_environment | d({}) }}'

    - name: Run Venom testsuites
      command: '{{ venom_dir }}/venom-wrapper.sh {{ venom_dir }}/test_suites/{{ item }}'
      args:
        chdir: '{{ venom_dir }}'
      loop: '{{ test_suites }}'
      vars:
        venom_wrapper_args:
          # temp, overcome Venom issue:
          # - when running test suite one by one, previous logs and results are overriden
          # Venom will create one directory per test suite to store results
          VENOM_COMMON_FLAGS: '--output-dir={{ venom_dir }}/results/{{ item }}'

      # add inventory__group_environment to Ansible environment
      # useful to make env vars available for Venom
      environment: '{{ inventory__group_environment | d({})
                       | combine(venom_wrapper_args | d({})) }}'

