@cryptotaxi247 / kubo / commits / c39b5a743

sharness: add function to test curl response

License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

Christian Couder committed Mar 8, 2015 at 17:25 UTC c39b5a7430b8470c7461f92e34a04f7c6c32232c
2 files changed +23 -8
test/sharness/lib/test-lib.sh
+21
@@ -255,3 +255,24 @@ test_kill_ipfs_daemon() {
255 test_kill_repeat_10_sec $IPFS_PID
256 '
257 }
258 +
259 +test_curl_resp_http_code() {
260 + curl -I "$1" >curl_output || {
261 + echo "curl error with url: '$1'"
262 + echo "curl output was:"
263 + cat curl_output
264 + return 1
265 + }
266 + shift &&
267 + RESP=$(head -1 curl_output) &&
268 + while test "$#" -gt 0
269 + do
270 + expr "$RESP" : "$1" >/dev/null && return
271 + shift
272 + done
273 + echo "curl response didn't match!"
274 + echo "curl response was: '$RESP'"
275 + echo "curl output was:"
276 + cat curl_output
277 + return 1
278 +}
test/sharness/t0110-gateway.sh
+2 -8
@@ -68,17 +68,11 @@ test_expect_success "GET invalid path errors" '
68 '
69
70 test_expect_success "GET /webui returns code expected" '
71 - curl -I http://127.0.0.1:$apiport/webui >actual &&
72 - RESP=$(head -1 actual) &&
73 - (expr "$RESP" : "HTTP/1.1 302 Found\s" ||
74 - expr "$RESP" : "HTTP/1.1 301 Moved Permanently\s")
71 + test_curl_resp_http_code "http://127.0.0.1:$apiport/webui" "HTTP/1.1 302 Found\s" "HTTP/1.1 301 Moved Permanently\s"
72 '
73
74 test_expect_success "GET /webui/ returns code expected" '
78 - curl -I http://127.0.0.1:$apiport/webui/ > actual &&
79 - RESP=$(head -1 actual) &&
80 - (expr "$RESP" : "HTTP/1.1 302 Found\s" ||
81 - expr "$RESP" : "HTTP/1.1 301 Moved Permanently\s")
75 + test_curl_resp_http_code "http://127.0.0.1:$apiport/webui/" "HTTP/1.1 302 Found\s" "HTTP/1.1 301 Moved Permanently\s"
76 '
77
78 test_kill_ipfs_daemon