1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 15:42:21 +08:00

sharness: add function to test curl response

License: MIT
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
This commit is contained in:
Christian Couder
2015-03-08 17:25:25 +01:00
parent ae35bd261c
commit c39b5a7430
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