mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-11 04:54:49 +08:00
sharness: add function to test curl response
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
This commit is contained in:
test/sharness
@ -255,3 +255,24 @@ test_kill_ipfs_daemon() {
|
|||||||
test_kill_repeat_10_sec $IPFS_PID
|
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" '
|
test_expect_success "GET /webui returns code expected" '
|
||||||
curl -I http://127.0.0.1:$apiport/webui >actual &&
|
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"
|
||||||
RESP=$(head -1 actual) &&
|
|
||||||
(expr "$RESP" : "HTTP/1.1 302 Found\s" ||
|
|
||||||
expr "$RESP" : "HTTP/1.1 301 Moved Permanently\s")
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success "GET /webui/ returns code expected" '
|
test_expect_success "GET /webui/ returns code expected" '
|
||||||
curl -I http://127.0.0.1:$apiport/webui/ > actual &&
|
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"
|
||||||
RESP=$(head -1 actual) &&
|
|
||||||
(expr "$RESP" : "HTTP/1.1 302 Found\s" ||
|
|
||||||
expr "$RESP" : "HTTP/1.1 301 Moved Permanently\s")
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_kill_ipfs_daemon
|
test_kill_ipfs_daemon
|
||||||
|
Reference in New Issue
Block a user