From f56348bcb2c736b9e66ebfe20c1f118cfc96b9f6 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 17 Apr 2015 12:58:56 +1000 Subject: [PATCH] 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 --- tests/test_ip.sh | 79 +++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/tests/test_ip.sh b/tests/test_ip.sh index add8d1ae65..c53e80de36 100755 --- a/tests/test_ip.sh +++ b/tests/test_ip.sh @@ -8,108 +8,111 @@ TOP=$(cd $(dirname "$0")/.. && pwd) # Import common functions source $TOP/functions +source $TOP/tests/unittest.sh echo "Testing IP addr functions" if [[ $(cidr2netmask 4) == 240.0.0.0 ]]; then - echo "cidr2netmask(): /4...OK" + passed "cidr2netmask(): /4...OK" else - echo "cidr2netmask(): /4...failed" + failed "cidr2netmask(): /4...failed" fi if [[ $(cidr2netmask 8) == 255.0.0.0 ]]; then - echo "cidr2netmask(): /8...OK" + passed "cidr2netmask(): /8...OK" else - echo "cidr2netmask(): /8...failed" + failed "cidr2netmask(): /8...failed" fi if [[ $(cidr2netmask 12) == 255.240.0.0 ]]; then - echo "cidr2netmask(): /12...OK" + passed "cidr2netmask(): /12...OK" else - echo "cidr2netmask(): /12...failed" + failed "cidr2netmask(): /12...failed" fi if [[ $(cidr2netmask 16) == 255.255.0.0 ]]; then - echo "cidr2netmask(): /16...OK" + passed "cidr2netmask(): /16...OK" else - echo "cidr2netmask(): /16...failed" + failed "cidr2netmask(): /16...failed" fi if [[ $(cidr2netmask 20) == 255.255.240.0 ]]; then - echo "cidr2netmask(): /20...OK" + passed "cidr2netmask(): /20...OK" else - echo "cidr2netmask(): /20...failed" + failed "cidr2netmask(): /20...failed" fi if [[ $(cidr2netmask 24) == 255.255.255.0 ]]; then - echo "cidr2netmask(): /24...OK" + passed "cidr2netmask(): /24...OK" else - echo "cidr2netmask(): /24...failed" + failed "cidr2netmask(): /24...failed" fi if [[ $(cidr2netmask 28) == 255.255.255.240 ]]; then - echo "cidr2netmask(): /28...OK" + passed "cidr2netmask(): /28...OK" else - echo "cidr2netmask(): /28...failed" + failed "cidr2netmask(): /28...failed" fi if [[ $(cidr2netmask 30) == 255.255.255.252 ]]; then - echo "cidr2netmask(): /30...OK" + passed "cidr2netmask(): /30...OK" else - echo "cidr2netmask(): /30...failed" + failed "cidr2netmask(): /30...failed" fi if [[ $(cidr2netmask 32) == 255.255.255.255 ]]; then - echo "cidr2netmask(): /32...OK" + passed "cidr2netmask(): /32...OK" else - echo "cidr2netmask(): /32...failed" + failed "cidr2netmask(): /32...failed" fi if [[ $(maskip 169.254.169.254 240.0.0.0) == 160.0.0.0 ]]; then - echo "maskip(): /4...OK" + passed "maskip(): /4...OK" else - echo "maskip(): /4...failed" + failed "maskip(): /4...failed" fi if [[ $(maskip 169.254.169.254 255.0.0.0) == 169.0.0.0 ]]; then - echo "maskip(): /8...OK" + passed "maskip(): /8...OK" else - echo "maskip(): /8...failed" + failed "maskip(): /8...failed" fi if [[ $(maskip 169.254.169.254 255.240.0.0) == 169.240.0.0 ]]; then - echo "maskip(): /12...OK" + passed "maskip(): /12...OK" else - echo "maskip(): /12...failed" + failed "maskip(): /12...failed" fi if [[ $(maskip 169.254.169.254 255.255.0.0) == 169.254.0.0 ]]; then - echo "maskip(): /16...OK" + passed "maskip(): /16...OK" else - echo "maskip(): /16...failed" + failed "maskip(): /16...failed" fi if [[ $(maskip 169.254.169.254 255.255.240.0) == 169.254.160.0 ]]; then - echo "maskip(): /20...OK" + passed "maskip(): /20...OK" else - echo "maskip(): /20...failed" + failed "maskip(): /20...failed" fi if [[ $(maskip 169.254.169.254 255.255.255.0) == 169.254.169.0 ]]; then - echo "maskip(): /24...OK" + passed "maskip(): /24...OK" else - echo "maskip(): /24...failed" + failed "maskip(): /24...failed" fi if [[ $(maskip 169.254.169.254 255.255.255.240) == 169.254.169.240 ]]; then - echo "maskip(): /28...OK" + passed "maskip(): /28...OK" else - echo "maskip(): /28...failed" + failed "maskip(): /28...failed" fi if [[ $(maskip 169.254.169.254 255.255.255.255) == 169.254.169.254 ]]; then - echo "maskip(): /32...OK" + passed "maskip(): /32...OK" else - echo "maskip(): /32...failed" + failed "maskip(): /32...failed" fi for mask in 8 12 16 20 24 26 28; do echo -n "address_in_net(): in /$mask..." if address_in_net 10.10.10.1 10.10.10.0/$mask; then - echo "OK" + passed "OK" else - echo "address_in_net() failed on /$mask" + failed "address_in_net() failed on /$mask" fi echo -n "address_in_net(): not in /$mask..." if ! address_in_net 10.10.10.1 11.11.11.0/$mask; then - echo "OK" + passed "OK" else - echo "address_in_net() failed on /$mask" + failed "address_in_net() failed on /$mask" fi done + +report_results