forked from talhasch/php-httpstat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpstat_test.sh
86 lines (66 loc) · 2.05 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
#!/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 ..."
}
http_url="google.com"
https_url="https://http2.akamai.com"
phpbin="php"
echo
echo "# Test in $phpbin"
function main() {
$phpbin httpstat.php $@ 2>&1
}
function main_silent() {
$phpbin httpstat.php $@ >/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_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