-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_tests
executable file
·189 lines (162 loc) · 3.58 KB
/
run_tests
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env bash
if [[ $# -gt 1 || $# -eq 1 && "$1" != --use-docker ]]
then
echo "Usage: $0 [--use-docker]"
exit 1
fi
if [ "$1" == --use-docker ]
then
start_server() {
docker run --rm -d --name=prnet_http_server_testing \
-e PRNET_MAX_IMAGE_SIZE=20000 -p 8000:8000 \
prnet_http_server:latest
}
stop_server() {
docker stop prnet_http_server_testing
}
else
start_server() {
cd "$(dirname "$0")"
PRNET_MAX_IMAGE_SIZE=20000 gunicorn prnet_wsgi:handle_request &
}
stop_server() {
kill %1; wait
}
fi
let failure_count=0
let test_count=0
report_testing_results()
{
echo '................................'
echo
echo "$test_count tests were run"
if [ "$failure_count" -ne 0 ]
then
echo "$failure_count of them failed :("
else
echo "All of them passed :)"
fi
echo
}
onexit()
{
stop_server
echo "PRNet HTTP server was stoped"
report_testing_results
}
echo "Starting PRNet HTTP server..."
start_server
trap 'onexit' EXIT
sleep 1
normalize()
{
sed '1 { /^HTTP\/1\.1 100 Continue/ {N;d}; }; s/\r$//'|
sed '1,/^$/ s/^\(Date\|Server\): .*/\1: ???/;
/^$/ {
N;N
p
s/.*/.../
p
N
: repeat
$q
N
s/[^\n]*\n//
b repeat;
}
'
}
curl()
{
command curl -sD - "$@"
}
check()
{
let ++test_count
echo "$@"
diff -U10 - <("$@"|normalize) || let ++failure_count
}
# GET request
check curl http://localhost:8000 <<'END'
HTTP/1.1 405 Method Not Allowed
Server: ???
Date: ???
Connection: close
Content-Length: 0
END
# POST to a non root path
check curl -F abc=def http://localhost:8000/xyz <<'END'
HTTP/1.1 405 Method Not Allowed
Server: ???
Date: ???
Connection: close
Content-Length: 0
END
# POST without image
check curl -F abc=def http://localhost:8000 <<'END'
HTTP/1.1 400 Bad Request
Server: ???
Date: ???
Connection: close
Content-Length: 0
END
# POST with image not a file
check curl -F image=def http://localhost:8000 <<'END'
HTTP/1.1 400 Bad Request
Server: ???
Date: ???
Connection: close
Content-Length: 0
END
# POST without content length
check curl -F abc=def -H 'Content-Length:' http://localhost:8000 <<'END'
HTTP/1.1 411 Length Required
Server: ???
Date: ???
Connection: close
Content-Length: 0
END
# POST with an image exceeding the max size limit
check curl -F image=@test_data/large_image.jpg http://localhost:8000 <<'END'
HTTP/1.1 413 Payload Too Large
Server: ???
Date: ???
Connection: close
Content-Length: 0
END
# POST valid data
check curl -F image=@test_data/single_face.jpg http://localhost:8000 <<'END'
HTTP/1.1 200 OK
Server: ???
Date: ???
Connection: close
Content-Type: application/octet-stream
Content-Length: 5532078
Content-Disposition: attachment; filename="single_face.jpg.obj"
v 140.088378906 301.859646331 104.281578064 0.529411764706 0.388235294118 0.286274509804
v 142.88794424 303.291693857 107.830162048 0.478431372549 0.321568627451 0.219607843137
...
f 43866 43867 43806
f 43867 43807 43806
END
# POST non-image data
check curl -F image=@"$0" http://localhost:8000 <<'END'
HTTP/1.1 500 Internal Server Error
Server: ???
Date: ???
Connection: close
Content-Type: application/json
Content-Length: 52
{"error": "cannot identify image file 'run_tests'"}
END
# POST a faceless image
check curl -F image=@test_data/no_face.jpg http://localhost:8000 <<'END'
HTTP/1.1 500 Internal Server Error
Server: ???
Date: ???
Connection: close
Content-Type: application/json
Content-Length: 34
{"error": "No face in the image"}
END
test "$failure_count" -eq 0