Skip to content

Instantly share code, notes, and snippets.

@zbentley
Last active February 7, 2018 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbentley/b7fae567de6a2542c709ca103c000802 to your computer and use it in GitHub Desktop.
Save zbentley/b7fae567de6a2542c709ca103c000802 to your computer and use it in GitHub Desktop.
Panzerbjörne
function testshit {
local testname="${1:?Test name needs to be first parameter bro}"
local url="${2:?URL needs to be second parameter bro}"
local regex="${3:?Regex needs to be third parameter bro}"
# Can do this multiple times if you want with different CURL args to e.g. test the headers/response code/body:
local curlout=$(curl -whatever "$url")
if echo "$curlout" | grep -P "$regex" >/dev/null; then
echo "$testname ($url): all good"
else
echo -e "$testname ($url): failed\nexpected to match: $regex\nInstead, got output:$curlout"
fi
}
testshit "my first test" "http://getfuct.org.biz" "^it's fucked br[oO]$"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment