Skip to content

Commit 3e0d98b

Browse files
committed
Fix and improve tests
1 parent ea08feb commit 3e0d98b

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

tests/dns-tests.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ apk add --no-cache --update bind-tools 1>/dev/null
77

88
EXIT_CODE=0
99

10+
# Arguments
11+
# - The name to query
12+
# - The exit code (default: 1)
13+
# - Some more options (default: none)
14+
#
1015
testQuery () {
11-
_RESULT="$(dig "$1" +noall +answer +short "@${DNS_SERVER}")"
16+
_RESULT="$(dig ${3:-} "$1" +noall +answer +short "@${DNS_SERVER}")"
1217
if [ -n "$_RESULT" ]; then
13-
echo "SUCCESS for $1"
18+
echo "SUCCESS for $1 ($_RESULT)"
1419
return;
1520
fi
1621
# Set exit code from second arg or use 1
1722
EXIT_CODE="${2:-1}"
18-
echo "FAILURE for $1"
23+
if [ "${2:-1}" = "0" ]; then
24+
echo "SUCCESS (successfully failed) for $1"
25+
else
26+
echo "FAILURE for $1"
27+
fi
1928
}
2029

2130
testServer() {
@@ -31,8 +40,14 @@ testServer() {
3140
# A query that only the server can answer
3241
testQuery 'test-domain.custom'
3342
testQuery 'dns-server.custom'
43+
testQuery '127.0.0.11' 0 '-x'
44+
testQuery '8.8.8.8' 0 '-x'
45+
testQuery '1.1.1.1' 0 '-x'
46+
47+
DNS_SERVER="127.0.0.11"
3448
# Using docker server
35-
testQuery 'dns-server' 1 127.0.0.11
49+
testQuery "${1}"
50+
DNS_SERVER="${1}"
3651

3752
echo 'Ended'
3853
}

0 commit comments

Comments
 (0)