From: Jonatan Schlag Date: Wed, 31 May 2017 13:03:05 +0000 (+0200) Subject: test: add test for function ip_detect_protocol X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=44fa36d7975c3c14d8b8821cee4a17c127faa60d;p=people%2Fjschlag%2Fnetwork.git test: add test for function ip_detect_protocol Signed-off-by: Jonatan Schlag --- diff --git a/test/functions/ip/ip_detect_protocol b/test/functions/ip/ip_detect_protocol new file mode 100755 index 0000000..47403f3 --- /dev/null +++ b/test/functions/ip/ip_detect_protocol @@ -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}