Merge pull request #895 from jbenet/sharness_check_curl_response

sharness: add function to test curl response
This commit is contained in:
Juan Batiz-Benet 2015-03-10 08:39:55 -07:00
commit e06016116d
2 changed files with 23 additions and 8 deletions

View File

@ -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
}

View File

@ -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