#! /bin/bash

full_path ()
{
	local b=$(basename "$1")
	pushd "$(dirname "$1")" > /dev/null
	echo "$(pwd)/$b"
	popd > /dev/null
}

rc=0
cd "$(dirname "$0")"
for confile in conf/*.cnf*
do
	echo
	echo "============================================================"
	echo "RUNNING TESTS FOR CONFIGURATION FILE conf/$confile"
	echo "============================================================"
	export VPNCONFIG=$(full_path "${confile}")
	failed=0
	all=0
	for tst in $(./dotest.sh 2> /dev/null | sed -e '1,4d')
	do
		echo -n "Running test $tst... "
		if ! ./dotest.sh "$tst" 2> /dev/null ; then
			rc=1
			echo FAILED
			(( failed++ ))
		else
			echo OK
		fi
		(( all++ ))
	done
	echo
	echo "===================================="
	echo "=======  $failed of $all test failed  ======="
	echo "===================================="
	echo
done

exit ${rc}
