Skip to content

Commit a649464

Browse files
authored
Merge pull request #118 from tomeon/test-suite-improvements
Test suite improvements
2 parents c79d33e + 493c879 commit a649464

37 files changed

+191
-121
lines changed

run-tests

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,36 @@
1414
# GNU General Public License for more details.
1515

1616
# Set colour escape sequences
17-
RED='\033[0;31m'
18-
YELLOW='\033[1;33m'
19-
ORANGE='\033[0;33m'
20-
GREEN='\033[0;32m'
21-
DARK='\033[1;30m'
22-
RESET='\033[0m'
17+
18+
PS4='+ ${BASH_SOURCE:-$0}@${LINENO:-0}${FUNCNAME:+#${FUNCNAME}()}: '
19+
20+
if [[ -n "${NO_COLOR:-}" ]] || ! colors="$(tput colors 2>/dev/null)" || (( "${colors:-0}" < 16 )); then
21+
RED=''
22+
YELLOW=''
23+
ORANGE=''
24+
GREEN=''
25+
DARK=''
26+
RESET=''
27+
else
28+
RED='\033[0;31m'
29+
YELLOW='\033[1;33m'
30+
ORANGE='\033[0;33m'
31+
GREEN='\033[0;32m'
32+
DARK='\033[1;30m'
33+
RESET='\033[0m'
34+
fi
35+
2336
# Set Pass/Fail signatures
2437
PASS=""
2538
FAIL=""
39+
2640
# Counters
2741
COUNT_PASS=0
2842
COUNT_FAIL=0
43+
44+
# Names of files in which test cases failed
45+
declare -A FAILED
46+
2947
# Flag for determining whether a test script called the `runtest' function
3048
RUNTEST_CALLED=0
3149

@@ -284,6 +302,9 @@ function _pass {
284302

285303
function _fail {
286304
COUNT_FAIL=$((COUNT_FAIL+1))
305+
if [[ -v TEST ]]; then
306+
FAILED["$TEST"]=1
307+
fi
287308
( >&2 echo -e " ${RED}${FAIL} ${@}${RESET}" )
288309
}
289310

@@ -342,16 +363,28 @@ evaltest() {
342363
TEST_BUSCTL_STATUS_RC=""
343364
# Keep this random, as we will never know the ifindex up-front
344365
ip_ifindex=$((RANDOM%=64))
366+
# Same for the device
367+
dev="tun${RANDOM}"
345368

346369
# Clear foreign_option_*
347-
for foreign_option_varname in "${!foreign_option_@}"; do
348-
declare "${foreign_option_varname}="
349-
done
370+
unset "${!foreign_option_@}"
350371

351372
# Import the test configuration
352-
source "${TEST}"
373+
source "${TEST}" || return
374+
375+
if (( RUNTEST_CALLED > 0 )); then
376+
return
377+
fi
378+
379+
declare -a foreign_options || return
380+
381+
local i=0
382+
local opt
383+
for opt in "${foreign_options[@]}" in; do
384+
declare "foreign_option_$(( i += 1 ))=${opt}"
385+
done
353386

354-
(( RUNTEST_CALLED > 0 )) || runtest
387+
runtest
355388
}
356389

357390
echo "update-systemd-resolved Test Suite"
@@ -376,5 +409,13 @@ done
376409
echo -e " ${GREEN}${PASS} ${COUNT_PASS} Passed${RESET}"
377410
echo -e " ${RED}${FAIL} ${COUNT_FAIL} Failed${RESET}"
378411

412+
if (( "${#FAILED[@]}" > 0 )); then
413+
echo -e "\n ${YELLOW}The following files have failing test cases:${RESET}"
414+
415+
for failed in "${!FAILED[@]}"; do
416+
echo -e " ${ORANGE}${failed}${RESET}"
417+
done
418+
fi
419+
379420
# Make sure we fail if there are failed tests
380421
[[ ${COUNT_FAIL} -eq 0 ]]

tests/01_no_updates.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Emulate OpenVPN environment
22
script_type="up"
3-
dev="tun01"
43

54
TEST_TITLE="No Updates"
65
TEST_BUSCTL_CALLED=1

tests/02_single_ipv4_dns.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
script_type="up"
2-
dev="tun02"
3-
foreign_option_1="dhcp-option DNS 1.23.4.56"
2+
3+
foreign_options=("dhcp-option DNS 1.23.4.56")
44

55
TEST_TITLE="Single IPv4 DNS Server"
66
TEST_BUSCTL_CALLED=1

tests/03a_multiple_ipv4_dns_1.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
script_type="up"
2-
dev="tun03"
3-
foreign_option_1="dhcp-option DNS 1.23.4.56"
4-
foreign_option_2="dhcp-option DNS 5.6.7.89"
2+
3+
4+
foreign_options=(
5+
"dhcp-option DNS 1.23.4.56"
6+
"dhcp-option DNS 5.6.7.89"
7+
)
58

69
TEST_TITLE="Multiple IPv4 DNS Servers (Part 1)"
710
TEST_BUSCTL_CALLED=1

tests/03b_multiple_ipv4_dns_2.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
script_type="up"
2-
dev="tun03"
3-
foreign_option_1="dhcp-option DNS 1.23.4.56"
4-
foreign_option_2="dhcp-option DNS 5.6.7.89"
5-
foreign_option_3="dhcp-option DNS 34.5.67.8"
2+
3+
foreign_options=(
4+
"dhcp-option DNS 1.23.4.56"
5+
"dhcp-option DNS 5.6.7.89"
6+
"dhcp-option DNS 34.5.67.8"
7+
)
68

79
TEST_TITLE="Multiple IPv4 DNS Servers (Part 2)"
810
TEST_BUSCTL_CALLED=1

tests/04a_single_dns_domain.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
script_type="up"
2-
dev="tun04"
3-
foreign_option_1="dhcp-option DOMAIN example.com"
2+
3+
foreign_options=("dhcp-option DOMAIN example.com")
44

55
TEST_TITLE="Single DNS Domain"
66
TEST_BUSCTL_CALLED=1

tests/04b_multiple_dns_domains.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
script_type="up"
2-
dev="tun04"
3-
foreign_option_1="dhcp-option DOMAIN example.com"
4-
foreign_option_2="dhcp-option DOMAIN example.co"
2+
3+
foreign_options=(
4+
"dhcp-option DOMAIN example.com"
5+
"dhcp-option DOMAIN example.co"
6+
)
57

68
TEST_TITLE="Multiple DNS Domains"
79
TEST_BUSCTL_CALLED=1

tests/05a_dns_domain_and_search_1.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
script_type="up"
2-
dev="tun05"
3-
foreign_option_1="dhcp-option DOMAIN example.com"
4-
foreign_option_2="dhcp-option DOMAIN-SEARCH example.org"
2+
3+
foreign_options=(
4+
"dhcp-option DOMAIN example.com"
5+
"dhcp-option DOMAIN-SEARCH example.org"
6+
)
57

68
TEST_TITLE="DNS Single Domain and Single Search"
79
TEST_BUSCTL_CALLED=1

tests/05b_dns_domain_and_search_2.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
script_type="up"
2-
dev="tun05"
3-
foreign_option_1="dhcp-option DOMAIN example.com"
4-
foreign_option_2="dhcp-option DOMAIN-SEARCH example.org"
5-
foreign_option_3="dhcp-option DOMAIN-SEARCH example.net"
2+
3+
foreign_options=(
4+
"dhcp-option DOMAIN example.com"
5+
"dhcp-option DOMAIN-SEARCH example.org"
6+
"dhcp-option DOMAIN-SEARCH example.net"
7+
)
68

79
TEST_TITLE="DNS Single Domain and Dual Search"
810
TEST_BUSCTL_CALLED=1

tests/05c_dns_domain_and_search_3.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
script_type="up"
2-
dev="tun05"
3-
foreign_option_1="dhcp-option DOMAIN-SEARCH example.org"
4-
foreign_option_2="dhcp-option DOMAIN example.com"
5-
foreign_option_3="dhcp-option DOMAIN-SEARCH example.net"
2+
3+
foreign_options=(
4+
"dhcp-option DOMAIN-SEARCH example.org"
5+
"dhcp-option DOMAIN example.com"
6+
"dhcp-option DOMAIN-SEARCH example.net"
7+
)
68

79
TEST_TITLE="DNS Single Domain and Dual Search (with Order Check)"
810
TEST_BUSCTL_CALLED=1

0 commit comments

Comments
 (0)