---
# Test to ensure the logging role successfully runs with the no given variables.
#
# [Configuration]
# No variables
#
# [Test scenario]
# 0. Run logging role.
#    If no variables are given, the logging role is not executed.
# 1. Check rsyslog.conf file size.
#    If logging role is _not_ executed, the original file size is about
#    3000 bytes.
#    Thus, assert the size is greater than 2000.
# 2. Check file count in /etc/rsyslog.d.
#    If logging role is _not_ executed, only configuration files only added
#    by other package could exist. That is usually 1 (RHEL8) or 2 (RHEL7).
#    Thus, assert the the count is less than or equal to 2.
# 3. Check systemctl status of rsyslog as well as error or specific message
#    in the output.
#
- name: Ensure that the role runs with default parameters
  hosts: all

  tasks:
    # rsyslog package may not be installed
    - name: Check if /etc/rsyslog.d exists
      stat:
        path: /etc/rsyslog.d
      register: rsyslog_d_dir

    - name: Check /etc/rsyslog.d
      command: ls /etc/rsyslog.d
      changed_when: false
      when: rsyslog_d_dir.stat.exists

    - name: Default run
      vars:
        logging_purge_confs: true
      include_role:
        name: fedora.linux_system_roles.logging

  # notify Restart rsyslogd is executed at the end of this test task.
  # thus we have to force to invoke handlers
    - name: "Force all notified handlers to run at this point, not waiting for normal sync points"
      meta: flush_handlers

    - name: Ensure config file size and counts
      vars:
        __conf_count: 0
        __conf_size: "{{ 'less' if __logging_is_ostree | d(false) else 'more' }}"
        __conf_files: []
        __check_systemctl_status: true
      include_tasks: tasks/check_daemon_config_files.yml
