Skip to content

Instantly share code, notes, and snippets.

@xcambar
Created October 18, 2014 13:41
Show Gist options
  • Save xcambar/a119a8ed985e14521f51 to your computer and use it in GitHub Desktop.
Save xcambar/a119a8ed985e14521f51 to your computer and use it in GitHub Desktop.
Mocking in shell scripts
#!/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