/
unit_test
executable file
·89 lines (70 loc) · 2.16 KB
/
unit_test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
#set -x
echo "-------------------- Start Unit Test --------------------"
set -e
set -o pipefail
set -o errtrace
echo "-------------------- Begin Sourcing --------------------"
for i in /usr/lib/sdwdate/modules.d/* /etc/sdwdate.d/*; do
if [ -f "$i" ]; then
## If the last character is a ~, ignore that file,
## because it was created by some editor,
## which creates backup files.
if [ "${i: -1}" = "~" ]; then
continue
fi
## Skipping files such as .dpkg-old and .dpkg-dist.
if ( echo "$i" | grep -q ".dpkg-" ); then
true "skip $i"
continue
fi
bash -n "$i"
source "$i"
fi
done
echo "-------------------- End Sourcing --------------------"
echo "-------------------- Begin Setup for Unit Test --------------------"
sdwdate_error_handler() {
local exit_code="$?"
local error_cause error_text
error_text="$1"
if [ "$error_text" = "" ]; then
error_cause="$FUNCNAME signal ERR detected with BASH_COMMAND:
$BASH_COMMAND"
else
error_cause="$FUNCNAME called with error_text:
$error_text"
fi
exit 1
}
trap "sdwdate_error_handler" ERR
sdwdate_log() {
true "$FUNCNAME (unit test): $@"
}
sdwdate_no_duplicate_log() {
true "$FUNCNAME (unit test): $@"
}
echo "-------------------- End Setup for Unit Test --------------------"
echo "-------------------- Begin Unit Test 1 --------------------"
download_unit_test() {
echo "-------------------- -------------------- --------------------"
#sdwdate_defaults
TEMP_DIR="/tmp/test"
SDWDATE_CURRENT_POOL="testpool"
mkdir --parents "$TEMP_DIR"
touch "$TEMP_DIR/$SDWDATE_CURRENT_POOL"
declare -A -g sdwdate_download_tool_exit_code
declare -A -g SDWDATE_DOWNLOAD_TOOL_PID
declare -A -g SDWDATE_DOWNLOAD_TOOK_TIME
i="0"
for element in "${SDWDATE_POOL_ONE[@]}" "${SDWDATE_POOL_TWO[@]}" "${SDWDATE_POOL_THREE[@]}"; do
i="$(( $i + 1 ))"
sdwdate_get_time_from_remote "$element"
if [ ! "${sdwdate_download_tool_exit_code[$SDWDATE_CURRENT_POOL]}" = "0" ]; then
echo "FAILED : $element"
else
echo "SUCCESS: $element"
fi
done
}
download_unit_test