]> git.ipfire.org Git - people/ms/network.git/commitdiff
test: add test for function ip_get_prefix
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Wed, 31 May 2017 13:03:34 +0000 (15:03 +0200)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Wed, 31 May 2017 13:03:34 +0000 (15:03 +0200)
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
test/functions/ip/ip_get_prefix [new file with mode: 0755]

diff --git a/test/functions/ip/ip_get_prefix b/test/functions/ip/ip_get_prefix
new file mode 100755 (executable)
index 0000000..3b0ad60
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+. ${networkdir}/functions
+
+. ${testdir}/constants.sh
+
+failed=0
+
+
+GET_PREFIX_TEST_VALID_ADRESSES=(
+       127.0.0.1/32
+       192.168.106.0/23
+       2001:470:1f09:1249::/64 
+       2001:470:6ef3::/48      
+       127.0.0.1
+)
+
+GET_PREFIX_TEST_VALID_PREFIXES=(
+       32
+       23
+       64
+       48
+       ""
+)
+
+i=0
+
+for address in ${GET_PREFIX_TEST_VALID_ADRESSES[@]}; do
+       prefix=$(ip_get_prefix ${address})      
+       if [[ $? == 0 ]] && [[ "${prefix}" == "${GET_PREFIX_TEST_VALID_PREFIXES[$i]}" ]]; then
+               echo "OK: Get prefix of ip ${address} was successful [${prefix}]"
+       else
+               echo "ERROR: Get prefix of ip ${address} was not successful [${prefix}]"
+               failed=1
+       fi
+       i=$(( i+1 ))
+done
+
+exit ${failed}