#!../common/bats/bin/bats
# -*-sh-*-

load ./common/test_helper_functions || exit 1
source ./common/functions || exit 1

if [ -s ./common/TEST_ENV ];then
    source ./common/TEST_ENV
fi

@test "[nhc] check for RPM" {
    run check_if_rpm_installed "nhc${DELIM}"
    assert_success
}

@test "[nhc] generate config file" {
    run which nhc-genconf
    assert_success

    run nhc-genconf
    if [ ! -f /etc/nhc/nhc.conf.auto ]; then
        flunk
    fi
}

@test "[nhc] service failure detection and restart" {
    grep rsyslog /etc/nhc/nhc.conf.auto > /etc/nhc/nhc.conf.rsyslog
    if [ "$DISTRO_FAMILY" == "SLES" ];then
	systemctl  stop syslog.socket
    else
	killall -w -s SIGTERM rsyslogd
    fi
    run nhc -c /etc/nhc/nhc.conf.rsyslog
    assert_failure
    run systemctl status rsyslog
    assert_success
}
