-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.sh
54 lines (43 loc) · 891 Bytes
/
common.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
50
51
52
53
54
SET() {
set +e
read -r -d '' $1
set -e
}
TEST() {
echo ">>> $@"
}
CURL_TMP=$(mktemp)
CURL_RSP_HEADERS="${CURL_TMP}-headers"
CURL_RSP_BODY="${CURL_TMP}-body"
REQ() {
curl ${TEST_SCHEME:-https}://${TEST_HOST:-localhost}:${TEST_PORT:-443}"$@" \
-k -s -S -v -o ${CURL_RSP_BODY} 2>&1 | tee ${CURL_TMP}
grep -E '^< \w+' ${CURL_TMP} | \
sed 's/< //g; s/ \r//g; s/\r//g' > ${CURL_RSP_HEADERS}
}
HEADER() {
grep "$@" ${CURL_RSP_HEADERS}
}
BODY() {
grep "$@" ${CURL_RSP_BODY}
}
JQ() {
jq -e "$@" < ${CURL_RSP_BODY}
}
GC_FN_LIST=()
GC() {
GC_FN_LIST+=("$@")
}
GC_CLEANUP() {
set +e
local tmp=()
for ((i=${#GC_FN_LIST[@]}-1; i>=0; i--)); do
eval "${GC_FN_LIST[$i]}"
done
set -e
}
GC "rm -f ${CURL_TMP}{,-headers,-body}"
trap GC_CLEANUP EXIT INT TERM
for ext in ${BURL_ROOT}/common.d/*.sh; do
. $ext
done