Commit c39b5a74 authored by Christian Couder's avatar Christian Couder

sharness: add function to test curl response

License: MIT
Signed-off-by: default avatarChristian Couder <chriscool@tuxfamily.org>
parent ae35bd26
......@@ -255,3 +255,24 @@ test_kill_ipfs_daemon() {
test_kill_repeat_10_sec $IPFS_PID
'
}
test_curl_resp_http_code() {
curl -I "$1" >curl_output || {
echo "curl error with url: '$1'"
echo "curl output was:"
cat curl_output
return 1
}
shift &&
RESP=$(head -1 curl_output) &&
while test "$#" -gt 0
do
expr "$RESP" : "$1" >/dev/null && return
shift
done
echo "curl response didn't match!"
echo "curl response was: '$RESP'"
echo "curl output was:"
cat curl_output
return 1
}
......@@ -68,17 +68,11 @@ test_expect_success "GET invalid path errors" '
'
test_expect_success "GET /webui returns code expected" '
curl -I http://127.0.0.1:$apiport/webui >actual &&
RESP=$(head -1 actual) &&
(expr "$RESP" : "HTTP/1.1 302 Found\s" ||
expr "$RESP" : "HTTP/1.1 301 Moved Permanently\s")
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"
'
test_expect_success "GET /webui/ returns code expected" '
curl -I http://127.0.0.1:$apiport/webui/ > actual &&
RESP=$(head -1 actual) &&
(expr "$RESP" : "HTTP/1.1 302 Found\s" ||
expr "$RESP" : "HTTP/1.1 301 Moved Permanently\s")
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"
'
test_kill_ipfs_daemon
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment