シェルスクリプトでリダイレクトのテストができるものを作った
シェルスクリプトでリダイレクトテストができるツールを作りました。その名も http_redirect_test.sh
というそのままの命名。
リダイレクトだけじゃなく、ステータスコード 200
、404
と 410
にも対応しています。
使い方
./http_redirect_test.sh [OPTIONS...] source_path destination_path
実行結果は、$?
で取れます。0
で成功、1
で失敗です。
Let’s try
リダイレクトだけのテスト
# Succeeded
./http_redirect_test.sh http://httpstat.us/301 http://httpstat.us
echo $? # 0
# Failed
./http_redirect_test.sh http://httpstat.us/302 http://httpstat.us/404
echo $? # 1
--status
オプションで、ステータスコードを指定
# Succeeded
./http_redirect_test.sh --status 301 http://httpstat.us/301 http://httpstat.us
echo $? # 0
ステータスコード 200のテスト
# Succeeded
./http_redirect_test.sh --status 200 http://httpstat.us/200
echo $? # 0
--debug
オプションでデバッグ
# Succeeded
./http_redirect_test.sh --debug http://httpstat.us/301 http://httpstat.us
# ---> http://httpstat.us/301
# Expected: status: url: http://httpstat.us
# Actual: status: 301, url_effective: http://httpstat.us, redirect_url: http://httpstat.us
echo $? # 0
もちろん一括テストもできちゃいます
#!/bin/sh
succeeded=0
failed=0
for source_destination in \
"http://httpstat.us/300" \
"http://httpstat.us/301 http://httpstat.us" \
"http://httpstat.us/302 http://httpstat.us" \
"http://httpstat.us/303 http://httpstat.us"
do
source=`echo $source_destination | cut -f1 -d" "`
destination=`echo $source_destination | cut -f2 -d" "`
./http_redirect_test.sh $source $destination
case $? in
0)
succeeded=`expr $succeeded + 1`
;;
*)
failed=`expr $failed + 1`
;;
esac
done
echo "succeeded: $succeeded, failed: $failed"
# succeeded: 4, failed: 0
その他
バグレポートや機能追加の PR
お待ちしてます!
Thanks
- Ruby で書かれた http_redirect_test に大変影響を受けています