2022-01-15 00:23:31 +01:00
|
|
|
set -g domain 'http://new.tojnar.cz'
|
|
|
|
|
set -g failed 0
|
|
|
|
|
|
|
|
|
|
function fail
|
|
|
|
|
set -l message $argv[1]
|
|
|
|
|
set -l output_file $argv[2]
|
|
|
|
|
echo "$message" > /dev/stderr
|
|
|
|
|
cat "$output_file" > /dev/stderr
|
|
|
|
|
set failed (math $failed + 1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function test_request
|
|
|
|
|
set -l uri $argv[1]
|
|
|
|
|
set -l argc (count $argv)
|
|
|
|
|
|
|
|
|
|
echo "Testing $domain$uri" > /dev/stderr
|
|
|
|
|
set output_file (mktemp)
|
|
|
|
|
curl --silent --location --head "$domain$uri" > "$output_file"
|
|
|
|
|
set last_status (cat "$output_file" | grep --perl-regexp 'HTTP/.+ \K([0-9]{3})' --only-matching | tail -n 1 | string trim)
|
|
|
|
|
set last_location (cat "$output_file" | grep --perl-regexp 'Location: \K(.+)' --only-matching | tail -n 1 | string trim)
|
|
|
|
|
|
|
|
|
|
set -l expected_status 200
|
|
|
|
|
if test "$argc" -ge 2
|
|
|
|
|
set expected_status $argv[2]
|
|
|
|
|
end
|
|
|
|
|
if test "$last_status" != "$expected_status"
|
|
|
|
|
fail "ERROR: Expected status $expected_status, $last_status received" "$output_file"
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if test "$argc" -ge 3
|
|
|
|
|
set -l expected_location $argv[3]
|
|
|
|
|
if test -z "$last_location"
|
|
|
|
|
fail "ERROR: Expected location $expected_location but no received" "$output_file"
|
|
|
|
|
return
|
|
|
|
|
else if test "$last_location" != "$domain$expected_location"
|
|
|
|
|
fail "ERROR: Expected location $expected_location, $last_location received" "$output_file"
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
else if test -n "$last_location"
|
|
|
|
|
fail "ERROR: Unexpected location $last_location received" "$output_file"
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
echo "OK" > /dev/stderr
|
|
|
|
|
echo > /dev/stderr
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test_request '/krk?lang=cs&page=krk_default' 200 '/krk/'
|
|
|
|
|
test_request '/krk?lang=en&page=krk_default' 200 '/krk/en/'
|
|
|
|
|
test_request '/krk?lang=cs' 200 '/krk/'
|
|
|
|
|
test_request '/krk?lang=en' 200 '/krk/en/'
|
|
|
|
|
test_request '/krk/mainkrk.php?page=clanky/beskydy-2010' 200 '/krk/clanky/beskydy-2010.html'
|
|
|
|
|
test_request '/krk/mainkrk.php?page=clanky/beskydy' 404 '/krk/clanky/beskydy.html'
|
|
|
|
|
test_request '/krk/?page=mcr_2009' 200 '/krk/mcr_2009/'
|
|
|
|
|
test_request '/krk/?page=mcr_2009/mcr_2009' 200 '/krk/mcr_2009/'
|
|
|
|
|
test_request '/krk/?page=mcr_2009/probihani_loucna/probihani_loucna' 200 '/krk/mcr_2009/probihani_loucna/'
|
|
|
|
|
test_request '/krk/?page=clanky' 200 '/krk/clanky/'
|
|
|
|
|
test_request '/krk/?page=clanky/clanky' 200 '/krk/clanky/'
|
|
|
|
|
test_request '/krk/?page=mcr_2009/' 200 '/krk/mcr_2009/'
|
|
|
|
|
test_request '/krk/?page=foo/' 404 '/krk/foo/'
|
|
|
|
|
test_request '/krk' 200 '/krk/'
|
|
|
|
|
test_request '/krk/cs/' 200 '/krk/'
|
|
|
|
|
test_request '/krk/en/'
|
|
|
|
|
test_request '/krk/en' 200 '/krk/en/'
|
|
|
|
|
test_request '/krk/cs' 200 '/krk/'
|
|
|
|
|
test_request '/krk/mainkrk.php' 200 '/krk/'
|
|
|
|
|
test_request '/krk/cs/mcr_2009/mcr_2009.html' 200 '/krk/mcr_2009/mcr_2009.html'
|
|
|
|
|
test_request '/krk/en/mcr_2009/mcr_2009.html'
|
|
|
|
|
test_request '/krk/clanky/beskydy-2010.html'
|
|
|
|
|
test_request '/krk/clanky/beskydy.html' 404
|
2022-01-18 08:31:13 +01:00
|
|
|
test_request '/krk/pages/mcr_2009/euro.gif' 200 '/krk/mcr_2009/euro.gif'
|
2022-01-15 00:23:31 +01:00
|
|
|
|
|
|
|
|
if test $failed = 0
|
|
|
|
|
echo "All tests passed" > /dev/stderr
|
|
|
|
|
else
|
|
|
|
|
echo "$failed tests failed" > /dev/stderr
|
|
|
|
|
exit 1
|
|
|
|
|
end
|