Use unittest help in test_ip.sh

Use the unittest helper to track test runs and correctly exit with a
failure code if there is a problem

Change-Id: Ie62f354a8cd3b8fd5986e6943a073f7955fb55ba
This commit is contained in:
Ian Wienand 2015-04-17 12:58:56 +10:00
parent 1cb809d8ef
commit f56348bcb2

View File

@ -8,108 +8,111 @@ TOP=$(cd $(dirname "$0")/.. && pwd)
# Import common functions # Import common functions
source $TOP/functions source $TOP/functions
source $TOP/tests/unittest.sh
echo "Testing IP addr functions" echo "Testing IP addr functions"
if [[ $(cidr2netmask 4) == 240.0.0.0 ]]; then if [[ $(cidr2netmask 4) == 240.0.0.0 ]]; then
echo "cidr2netmask(): /4...OK" passed "cidr2netmask(): /4...OK"
else else
echo "cidr2netmask(): /4...failed" failed "cidr2netmask(): /4...failed"
fi fi
if [[ $(cidr2netmask 8) == 255.0.0.0 ]]; then if [[ $(cidr2netmask 8) == 255.0.0.0 ]]; then
echo "cidr2netmask(): /8...OK" passed "cidr2netmask(): /8...OK"
else else
echo "cidr2netmask(): /8...failed" failed "cidr2netmask(): /8...failed"
fi fi
if [[ $(cidr2netmask 12) == 255.240.0.0 ]]; then if [[ $(cidr2netmask 12) == 255.240.0.0 ]]; then
echo "cidr2netmask(): /12...OK" passed "cidr2netmask(): /12...OK"
else else
echo "cidr2netmask(): /12...failed" failed "cidr2netmask(): /12...failed"
fi fi
if [[ $(cidr2netmask 16) == 255.255.0.0 ]]; then if [[ $(cidr2netmask 16) == 255.255.0.0 ]]; then
echo "cidr2netmask(): /16...OK" passed "cidr2netmask(): /16...OK"
else else
echo "cidr2netmask(): /16...failed" failed "cidr2netmask(): /16...failed"
fi fi
if [[ $(cidr2netmask 20) == 255.255.240.0 ]]; then if [[ $(cidr2netmask 20) == 255.255.240.0 ]]; then
echo "cidr2netmask(): /20...OK" passed "cidr2netmask(): /20...OK"
else else
echo "cidr2netmask(): /20...failed" failed "cidr2netmask(): /20...failed"
fi fi
if [[ $(cidr2netmask 24) == 255.255.255.0 ]]; then if [[ $(cidr2netmask 24) == 255.255.255.0 ]]; then
echo "cidr2netmask(): /24...OK" passed "cidr2netmask(): /24...OK"
else else
echo "cidr2netmask(): /24...failed" failed "cidr2netmask(): /24...failed"
fi fi
if [[ $(cidr2netmask 28) == 255.255.255.240 ]]; then if [[ $(cidr2netmask 28) == 255.255.255.240 ]]; then
echo "cidr2netmask(): /28...OK" passed "cidr2netmask(): /28...OK"
else else
echo "cidr2netmask(): /28...failed" failed "cidr2netmask(): /28...failed"
fi fi
if [[ $(cidr2netmask 30) == 255.255.255.252 ]]; then if [[ $(cidr2netmask 30) == 255.255.255.252 ]]; then
echo "cidr2netmask(): /30...OK" passed "cidr2netmask(): /30...OK"
else else
echo "cidr2netmask(): /30...failed" failed "cidr2netmask(): /30...failed"
fi fi
if [[ $(cidr2netmask 32) == 255.255.255.255 ]]; then if [[ $(cidr2netmask 32) == 255.255.255.255 ]]; then
echo "cidr2netmask(): /32...OK" passed "cidr2netmask(): /32...OK"
else else
echo "cidr2netmask(): /32...failed" failed "cidr2netmask(): /32...failed"
fi fi
if [[ $(maskip 169.254.169.254 240.0.0.0) == 160.0.0.0 ]]; then if [[ $(maskip 169.254.169.254 240.0.0.0) == 160.0.0.0 ]]; then
echo "maskip(): /4...OK" passed "maskip(): /4...OK"
else else
echo "maskip(): /4...failed" failed "maskip(): /4...failed"
fi fi
if [[ $(maskip 169.254.169.254 255.0.0.0) == 169.0.0.0 ]]; then if [[ $(maskip 169.254.169.254 255.0.0.0) == 169.0.0.0 ]]; then
echo "maskip(): /8...OK" passed "maskip(): /8...OK"
else else
echo "maskip(): /8...failed" failed "maskip(): /8...failed"
fi fi
if [[ $(maskip 169.254.169.254 255.240.0.0) == 169.240.0.0 ]]; then if [[ $(maskip 169.254.169.254 255.240.0.0) == 169.240.0.0 ]]; then
echo "maskip(): /12...OK" passed "maskip(): /12...OK"
else else
echo "maskip(): /12...failed" failed "maskip(): /12...failed"
fi fi
if [[ $(maskip 169.254.169.254 255.255.0.0) == 169.254.0.0 ]]; then if [[ $(maskip 169.254.169.254 255.255.0.0) == 169.254.0.0 ]]; then
echo "maskip(): /16...OK" passed "maskip(): /16...OK"
else else
echo "maskip(): /16...failed" failed "maskip(): /16...failed"
fi fi
if [[ $(maskip 169.254.169.254 255.255.240.0) == 169.254.160.0 ]]; then if [[ $(maskip 169.254.169.254 255.255.240.0) == 169.254.160.0 ]]; then
echo "maskip(): /20...OK" passed "maskip(): /20...OK"
else else
echo "maskip(): /20...failed" failed "maskip(): /20...failed"
fi fi
if [[ $(maskip 169.254.169.254 255.255.255.0) == 169.254.169.0 ]]; then if [[ $(maskip 169.254.169.254 255.255.255.0) == 169.254.169.0 ]]; then
echo "maskip(): /24...OK" passed "maskip(): /24...OK"
else else
echo "maskip(): /24...failed" failed "maskip(): /24...failed"
fi fi
if [[ $(maskip 169.254.169.254 255.255.255.240) == 169.254.169.240 ]]; then if [[ $(maskip 169.254.169.254 255.255.255.240) == 169.254.169.240 ]]; then
echo "maskip(): /28...OK" passed "maskip(): /28...OK"
else else
echo "maskip(): /28...failed" failed "maskip(): /28...failed"
fi fi
if [[ $(maskip 169.254.169.254 255.255.255.255) == 169.254.169.254 ]]; then if [[ $(maskip 169.254.169.254 255.255.255.255) == 169.254.169.254 ]]; then
echo "maskip(): /32...OK" passed "maskip(): /32...OK"
else else
echo "maskip(): /32...failed" failed "maskip(): /32...failed"
fi fi
for mask in 8 12 16 20 24 26 28; do for mask in 8 12 16 20 24 26 28; do
echo -n "address_in_net(): in /$mask..." echo -n "address_in_net(): in /$mask..."
if address_in_net 10.10.10.1 10.10.10.0/$mask; then if address_in_net 10.10.10.1 10.10.10.0/$mask; then
echo "OK" passed "OK"
else else
echo "address_in_net() failed on /$mask" failed "address_in_net() failed on /$mask"
fi fi
echo -n "address_in_net(): not in /$mask..." echo -n "address_in_net(): not in /$mask..."
if ! address_in_net 10.10.10.1 11.11.11.0/$mask; then if ! address_in_net 10.10.10.1 11.11.11.0/$mask; then
echo "OK" passed "OK"
else else
echo "address_in_net() failed on /$mask" failed "address_in_net() failed on /$mask"
fi fi
done done
report_results