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

diff --git a/test/functions/ip/ip_detect_protocol b/test/functions/ip/ip_detect_protocol
new file mode 100755 (executable)
index 0000000..47403f3
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+. ${networkdir}/functions
+
+. ${testdir}/constants.sh
+
+failed=0
+
+for address in ${VALID_IPv4_ADDRESSES[@]}; do
+       proto=$(ip_detect_protocol ${address})
+       if [[ $? == 0 ]] && [[ "${proto}" == "ipv4" ]]; then
+               echo "OK: Detection of ip protocol for ${address} was successful [${proto}]"
+       else
+               echo "ERROR: Detection of ip protocol for ${address} was not successful"
+               failed=1
+       fi
+done
+
+# Here we have to use a extra array because ::1 is an invalid IPv4 address but we can find a protocol for it [ipv6], so ip_detect_protocol is successful
+INVALID_IPv4_ADDRESSES=(
+       1.2.3.X/abc
+       a.b.c.d/24
+       a.b.c.d/e
+       1.2.3.500
+)
+
+for address in ${INVALID_IPv4_ADDRESSES[@]}; do
+       proto=$(ip_detect_protocol ${address})
+       if [[ $? == 1 ]] && [[ "${proto}" != "ipv4" ]]; then
+               echo "OK: Detection of ip protocol for ${address} was not successful"
+       else
+               echo "ERROR: Detection of ip protocol for ${address} was successful [${proto}]"
+               failed=1
+       fi
+done
+
+exit ${failed}