# #-- log_servfail.test --#
# source the master var file when it's there
[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
# use .tpkg.var.test for in test variable passing
[ -f .tpkg.var.test ] && source .tpkg.var.test
PRE="../.."
. ../common.sh

outfile=dig.out

teststep "Check if log-servfail logs to output for iterator error"
dig a.servfail @127.0.0.1 -p $SERVER_PORT > $outfile
if ! grep "SERVFAIL" $outfile
then
	cat $outfile
	echo "Did not get a SERVFAIL response"
	exit 1
fi
if ! grep "SERVFAIL <a\.servfail\. "  unbound.log
then
        echo "No log-servfail in output"
        exit 1
fi

teststep "Enable serve expired"
$PRE/unbound-control -c ub.conf set_option serve-expired: yes
if test $? -ne 0
then
	echo "unbound-control command exited with non-zero error code"
	exit 1
fi

teststep "Check if log-servfail logs to output for iterator error (with serve-expired)"
dig b.servfail @127.0.0.1 -p $SERVER_PORT > $outfile
if ! grep "SERVFAIL" $outfile
then
	cat $outfile
	echo "Did not get a SERVFAIL response"
	exit 1
fi
if ! grep "SERVFAIL <b\.servfail\. "  unbound.log
then
        echo "No log-servfail in output"
        exit 1
fi

exit 0
