-
Notifications
You must be signed in to change notification settings - Fork 386
/
httpstat_test.sh
executable file
·110 lines (87 loc) · 2.75 KB
/
httpstat_test.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
function assert_exit() {
rc=$?
expect=$1
if [ "$rc" -eq "$expect" ]; then
echo OK
else
echo "Failed, expect $expect, got $rc"
exit 1
fi
}
function title() {
echo
echo "Test $1 ..."
}
function check_url() {
url=$1
echo "Checking $url ..."
if curl -s --head "$url" >/dev/null; then
echo "URL $url is accessible"
else
echo "URL $url is not accessible"
exit 1
fi
}
http_url="www.gstatic.com/generate_204"
https_url="https://http2.akamai.com"
check_url "$http_url"
check_url "$https_url"
for pybin in python python3; do
#for pybin in python; do
echo
echo "# Test in $pybin"
function main() {
$pybin httpstat.py $@ 2>&1
}
function main_silent() {
$pybin httpstat.py $@ >/dev/null 2>&1
}
title "basic"
main_silent $http_url
assert_exit 0
title "https site ($https_url)"
main_silent $https_url
assert_exit 0
title "comma decimal language (ru_RU)"
LC_ALL=ru_RU main_silent $http_url
assert_exit 0
title "HTTPSTAT_DEBUG"
HTTPSTAT_DEBUG=true main $http_url | grep -q 'HTTPSTAT_DEBUG=true'
assert_exit 0
title "HTTPSTAT_SHOW_SPEED"
HTTPSTAT_SHOW_SPEED=true main $http_url | grep -q 'speed_download'
assert_exit 0
title "HTTPSTAT_CURL_BIN"
HTTPSTAT_CURL_BIN=/usr/bin/curl HTTPSTAT_DEBUG=true main $http_url | grep -q '/usr/bin/curl'
assert_exit 0
title "HTTPSTAT_SHOW_IP"
HTTPSTAT_SHOW_IP="true" main $http_url | grep -q 'Connected'
assert_exit 0
title "HTTPSTAT_SHOW_BODY=true, -G --data-urlencode \"a=中文\""
HTTPSTAT_SHOW_BODY="true" main_silent httpbin.org/get -G --data-urlencode "a=中文"
assert_exit 0
title "HTTPSTAT_SHOW_BODY=true, -G --data-urlencode \"a=中文\""
HTTPSTAT_SHOW_BODY="true" main_silent httpbin.org/post -X POST --data-urlencode "a=中文"
assert_exit 0
title "HTTPSTAT_SAVE_BODY=true"
HTTPSTAT_SAVE_BODY=true main $http_url | grep -q 'stored in'
assert_exit 0
title "HTTPSTAT_SAVE_BODY=false"
HTTPSTAT_SAVE_BODY=false HTTPSTAT_DEBUG=true main $http_url | grep -q 'rm body file'
assert_exit 0
title "HTTPSTAT_SHOW_BODY=true HTTPSTAT_SAVE_BODY=true, has 'is truncated, has 'stored in'"
out=$(HTTPSTAT_SHOW_BODY=true HTTPSTAT_SAVE_BODY=true \
main $https_url)
echo "$out" | grep -q 'is truncated'
assert_exit 0
echo "$out" | grep -q 'stored in'
assert_exit 0
title "HTTPSTAT_SHOW_BODY=true HTTPSTAT_SAVE_BODY=false, has 'is truncated', no 'stored in'"
out=$(HTTPSTAT_SHOW_BODY=true HTTPSTAT_SAVE_BODY=false \
main $https_url)
echo "$out" | grep -q 'is truncated'
assert_exit 0
echo "$out" | grep -q 'stored in'
assert_exit 1
done