Created
September 17, 2019 12:39
-
-
Save hugocf/51ac6cf97e76bc70d218be8b9a0eae75 to your computer and use it in GitHub Desktop.
Choose site to run based on a list of fixed site codes
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
❌ Error for site 'site1' because filter is 'gibberish' | |
✅ Testing site 'site1' because filter is '' | |
✅ Testing site 'site1' because filter is 'site1' | |
🙈 Skipping site 'site1' because filter is 'site2' | |
🙈 Skipping site 'site1' because filter is 'site3' | |
🙈 Skipping site 'site1' because filter is 'site4' | |
❌ Error for site 'site2' because filter is 'gibberish' | |
✅ Testing site 'site2' because filter is '' | |
🙈 Skipping site 'site2' because filter is 'site1' | |
✅ Testing site 'site2' because filter is 'site2' | |
🙈 Skipping site 'site2' because filter is 'site3' | |
🙈 Skipping site 'site2' because filter is 'site4' | |
❌ Error for site 'site3' because filter is 'gibberish' | |
✅ Testing site 'site3' because filter is '' | |
🙈 Skipping site 'site3' because filter is 'site1' | |
🙈 Skipping site 'site3' because filter is 'site2' | |
✅ Testing site 'site3' because filter is 'site3' | |
🙈 Skipping site 'site3' because filter is 'site4' | |
❌ Error for site 'site4' because filter is 'gibberish' | |
✅ Testing site 'site4' because filter is '' | |
🙈 Skipping site 'site4' because filter is 'site1' | |
🙈 Skipping site 'site4' because filter is 'site2' | |
🙈 Skipping site 'site4' because filter is 'site3' | |
✅ Testing site 'site4' because filter is 'site4' |
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
#!/usr/bin/env bash | |
set -u | |
ACTION=./choose-site-to-run.sh | |
EXPECTED=./choose-site-to-run-expected.txt | |
RESULT=$(mktemp) | |
$ACTION > $RESULT | |
if diff -u $EXPECTED $RESULT; then | |
echo "Success: all results match" | |
fi |
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
#!/usr/bin/env bash | |
set -u | |
choose_site () { | |
# choose_site_with_if ${1:-} ${2:-} | |
# choose_site_with_case ${1:-} ${2:-} | |
choose_site_with_guard ${1:-} ${2:-} | |
} | |
choose_site_with_if () { | |
local SITE_CODE=${1:-} | |
local FILTER=${2:-} | |
if [[ "$FILTER" == "" || "$FILTER" == "$SITE_CODE" ]]; then | |
echo "✅ Testing site '$SITE_CODE' because filter is '$FILTER'" | |
elif [[ "$FILTER" == "site1" || "$FILTER" == "site2" || "$FILTER" == "site3" || "$FILTER" == "site4" ]]; then | |
echo "🙈 Skipping site '$SITE_CODE' because filter is '$FILTER'" | |
else | |
echo "❌ Error for site '$SITE_CODE' because filter is '$FILTER'" | |
# exit 1 | |
fi | |
} | |
choose_site_with_case () { | |
local SITE_CODE=${1:-} | |
local FILTER=${2:-} | |
case $FILTER in | |
"" | $SITE_CODE) | |
echo "✅ Testing site '$SITE_CODE' because filter is '$FILTER'";; | |
site1 | site2 | site3 | site4) | |
echo "🙈 Skipping site '$SITE_CODE' because filter is '$FILTER'";; | |
*) | |
echo "❌ Error for site '$SITE_CODE' because filter is '$FILTER'" | |
# exit 1 | |
;; | |
esac | |
} | |
choose_site_with_guard () { | |
local SITE_CODE=${1:-} | |
local FILTER=${2:-} | |
local ALLOWED_SITE_CODES="^(site1|site2|site3|site4)$" | |
if ! [[ $FILTER == "" || "$FILTER" =~ $ALLOWED_SITE_CODES ]]; then | |
echo "❌ Error for site '$SITE_CODE' because filter is '$FILTER'" | |
return # exit 1 | |
fi | |
case $FILTER in | |
"" | $SITE_CODE) echo "✅ Testing site '$SITE_CODE' because filter is '$FILTER'";; | |
*) echo "🙈 Skipping site '$SITE_CODE' because filter is '$FILTER'";; | |
esac | |
} | |
choose_site site1 gibberish | |
choose_site site1 | |
choose_site site1 site1 | |
choose_site site1 site2 | |
choose_site site1 site3 | |
choose_site site1 site4 | |
echo | |
choose_site site2 gibberish | |
choose_site site2 | |
choose_site site2 site1 | |
choose_site site2 site2 | |
choose_site site2 site3 | |
choose_site site2 site4 | |
echo | |
choose_site site3 gibberish | |
choose_site site3 | |
choose_site site3 site1 | |
choose_site site3 site2 | |
choose_site site3 site3 | |
choose_site site3 site4 | |
echo | |
choose_site site4 gibberish | |
choose_site site4 | |
choose_site site4 site1 | |
choose_site site4 site2 | |
choose_site site4 site3 | |
choose_site site4 site4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment