Created
October 8, 2018 09:06
-
-
Save timgentry/2a2274903c7f74711887c459f822304c to your computer and use it in GitHub Desktop.
A bash script providing test assertions on the status code of http(s) requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function assert_http_status { | |
local HTTP_CODE=$(curl -o /dev/null --silent --head --write-out '%{http_code}\n' $2) | |
echo "$2 returned status code $HTTP_CODE" | |
test $HTTP_CODE != $1 && (echo "FAIL: Expected $1"; exit 1) | |
echo | |
} | |
assert_http_status "200" "https://www.bbc.co.uk/" | |
assert_http_status "200" "https://bbc.co.uk/" # This will fail with 301 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment