-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
38 lines (28 loc) · 764 Bytes
/
test.sh
File metadata and controls
38 lines (28 loc) · 764 Bytes
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
#!/bin/bash
set -o nounset
prog=./httpd
PORT=8080
function error() {
echo "$@" >&2
exit 1
}
# show version
echo './httpd 0.1.0' | cmp - <(./httpd -v 2>&1) || error "$LINENO"
# start server
$prog -p $PORT &
# Normal request
curl -s --head 127.0.0.1:${PORT}/hello.html | head -1 | grep 200 > /dev/null || error "$LINENO"
# Not Found
curl -s --head 127.0.0.1:${PORT}/not_found | head -1 | grep 404 > /dev/null || error "$LINENO"
# Empty request
echo -n | telnet 127.0.0.1 ${PORT} 2>/dev/null | cmp - <<EOF
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
EOF
[[ $? != 0 ]] && error "$LINENO"
# stop server
kill %1
echo "=============================="
echo " All functional tests passed."
echo "=============================="