Skip to content

Commit 23fecf2

Browse files
authored
initial regression test framework (#90)
1 parent dedba4d commit 23fecf2

File tree

3 files changed

+718
-1
lines changed

3 files changed

+718
-1
lines changed

tests/test.sh

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/bin/bash
2+
3+
filename="wt-tests.md"
4+
client_container="wiretap-client-1"
5+
server_container="wiretap-server-1"
6+
target_container="wiretap-target-1"
7+
8+
if [[ ! -f "$filename" ]]; then
9+
echo "'$filename' not found"
10+
exit 1
11+
fi
12+
13+
function doClient() {
14+
echo "[C] $1"
15+
bg=""
16+
if [[ "${1: -1}" == "&" ]]; then
17+
bg="-d"
18+
# Remove the trailing '&' for the command execution
19+
cmd="${1:0:-1}"
20+
echo "[C BG] $cmd"
21+
else
22+
cmd="$1"
23+
fi
24+
docker exec $bg "$client_container" bash -c "$cmd"
25+
}
26+
27+
function doServer() {
28+
echo "[S] $1"
29+
bg=""
30+
if [[ "${1: -1}" == "&" ]]; then
31+
bg="-d"
32+
# Remove the trailing '&' for the command execution
33+
cmd="${1:0:-1}"
34+
echo "[S BG] $cmd"
35+
else
36+
cmd="$1"
37+
fi
38+
docker exec $bg "$server_container" bash -c "$cmd"
39+
}
40+
41+
function doTarget() {
42+
echo "[T] $1"
43+
bg=""
44+
if [[ "${1: -1}" == "&" ]]; then
45+
bg="-d"
46+
# Remove the trailing '&' for the command execution
47+
cmd="${1:0:-1}"
48+
echo "[T BG] $cmd"
49+
else
50+
cmd="$1"
51+
fi
52+
53+
docker exec $bg "$target_container" bash -c "$cmd"
54+
}
55+
56+
function copyToServer() {
57+
local src="$1"
58+
local dest="$2"
59+
docker cp "$client_container":"$src" /tmp/wt.tmp
60+
#docker cp /tmp/wt.tmp "$server_container":"$dest"
61+
docker cp /tmp/wt.tmp "$server_container":"$src"
62+
rm /tmp/wt.tmp
63+
}
64+
65+
function copyToTarget() {
66+
local src="$1"
67+
local dest="$2"
68+
docker cp "$client_container":"$src" /tmp/wt.tmp
69+
docker cp /tmp/wt.tmp "$target_container":"$src"
70+
rm /tmp/wt.tmp
71+
}
72+
73+
running=0
74+
75+
while IFS= read -r line
76+
do
77+
if [[ "$line" == '#'* ]]; then
78+
echo "$line"
79+
continue
80+
fi
81+
82+
if [[ "$line" == '```'* ]]; then
83+
#echo "Line starts with three backticks"
84+
if [[ $running -eq 1 ]]; then
85+
echo "End test"
86+
echo
87+
echo
88+
running=0
89+
continue
90+
fi
91+
92+
running=1
93+
echo "Starting a new test"
94+
continue
95+
fi
96+
97+
if [[ $running -eq 1 ]]; then
98+
99+
if [[ "$line" == 'COPYCONF'* ]]; then
100+
mapfile -t conf_list < <(docker exec "$client_container" bash -c 'find /wiretap -type f -name "wiretap_server*.conf"')
101+
for conf in "${conf_list[@]}"; do
102+
copyToServer $conf /wiretap/
103+
copyToTarget $conf /wiretap/
104+
done
105+
106+
continue
107+
fi
108+
109+
if [[ "$line" == 'WAIT'* ]]; then
110+
wait_arg=$(echo "$line" | awk '{print $2}')
111+
echo "Waiting for $wait_arg seconds..."
112+
sleep "$wait_arg"
113+
continue
114+
fi
115+
116+
if [[ "$line" == 'EXIT'* ]]; then
117+
exit 0
118+
fi
119+
120+
cmd="${line:1}"
121+
if [[ "$line" == '!'* ]]; then
122+
doClient "$cmd"
123+
sleep 0.5
124+
125+
elif [[ "$line" == '@'* ]]; then
126+
doServer "$cmd"
127+
sleep 0.5
128+
129+
elif [[ "$line" == '%'* ]]; then
130+
doTarget "$cmd"
131+
sleep 0.5
132+
fi
133+
fi
134+
135+
done < "$filename"

0 commit comments

Comments
 (0)