-
-
Save Oyonax/de4fe10d73d32aaf73bd to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
URL=http://localhost:8080 | |
## Unit-Testable Shell Scripts (http://eradman.com/posts/ut-shell-scripts.html) | |
typeset -i tests_run=0 | |
function try { this="$1"; } | |
trap 'printf "$0: exit code $? on line $LINENO\nFAIL: $this\n"; exit 1' ERR | |
function assert { | |
let tests_run+=1 | |
[ "$1" = "$2" ] && { echo -n "."; return; } | |
printf "\nFAIL: $this\n'$1' != '$2'\n"; exit 1 | |
} | |
## end | |
############################################################### | |
try "Example of GET and test for 404 status" | |
out=$(curl -s -w "%{http_code}" $URL) | |
assert "404" "$out" | |
try "Example of POST XML" | |
# Post xml (from hello.xml file) on /hello | |
out=$(cat test/hello.xml | curl -s -H "Content-Type: text/xml" -d @- \ | |
-X POST $URL/hello) | |
assert "Hello World" "$out" | |
############################################################### | |
echo | |
echo "PASS: $tests_run tests run" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment