diff --git a/test/sharness/lib/test-lib.sh b/test/sharness/lib/test-lib.sh index bc1be0be9..61a0a7665 100644 --- a/test/sharness/lib/test-lib.sh +++ b/test/sharness/lib/test-lib.sh @@ -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 +} diff --git a/test/sharness/t0110-gateway.sh b/test/sharness/t0110-gateway.sh index 4f2c33028..a677ee5ae 100755 --- a/test/sharness/t0110-gateway.sh +++ b/test/sharness/t0110-gateway.sh @@ -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