Skip to content

Instantly share code, notes, and snippets.

@timgentry
Created October 8, 2018 09:06
Show Gist options
  • Save timgentry/2a2274903c7f74711887c459f822304c to your computer and use it in GitHub Desktop.
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
#!/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