forked from envoyproxy/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify_examples.sh
executable file
·49 lines (42 loc) · 1.18 KB
/
verify_examples.sh
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
#!/bin/bash -e
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
RETURNS=0
trim () {
text=$(< /dev/stdin)
echo -n "$text" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//'
}
pass () {
local timing="${1}"
echo "${GREEN}passed${NC} in ${timing}"
}
fail () {
local timing="${1}" exitcode="${2}"
echo "${RED}failed (${exitcode})${NC} in ${timing}"
}
for result in "$@"; do
RESULT="$(head -n1 "$result")"
NAME="$(echo "${RESULT}" | cut -d: -f1 | trim)"
EXITCODE="$(echo "${RESULT}" | cut -d: -f2 | trim)"
if [[ $EXITCODE != 0 ]]; then
echo
echo -e "============= ${RED}FAILED (${NAME})${NC} ===================="
tail -n+3 "$result"
echo -e "============ ${RED}/FAILED (${NAME})${NC} ===================="
echo
fi
done
for result in "$@"; do
RESULT=$(head -n1 "$result")
NAME="$(echo "${RESULT}" | cut -d: -f1 | trim)"
EXITCODE="$(echo "${RESULT}" | cut -d: -f2 | trim)"
TIME="$(echo "${RESULT}" | cut -d: -f3 | trim)"
OUTCOME=$(pass "${TIME}")
if [[ $EXITCODE != 0 ]]; then
OUTCOME=$(fail "${TIME}" "$EXITCODE")
RETURNS=1
fi
echo -e "${NAME}: ${OUTCOME}"
done
exit "${RETURNS}"