Created
October 18, 2014 13:41
-
-
Save xcambar/a119a8ed985e14521f51 to your computer and use it in GitHub Desktop.
Mocking in shell scripts
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 | |
shopt -s expand_aliases | |
curl_mock() { | |
local success | |
[ "$1" == "success" ] && success=0 || success=1 | |
shift | |
if [ $success -eq 0 ]; then | |
echo "SUCCESS with args $*"; | |
else | |
echo "FAILURE with args $*"; | |
fi | |
return $success; | |
} | |
alias curl="curl_mock success $*" | |
curl BLA BLA BLA | |
alias curl="curl_mock failure $*" | |
curl TOO BAD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment