From b5b89bc7d6cc25898bfcd923083011305b8b248d Mon Sep 17 00:00:00 2001 From: Thorsten Bro Date: Feb 05 2018 23:09:09 +0000 Subject: Merge branch 'tests_colors' into 'production' tests: colorize the output See merge request infra/salt!176 --- diff --git a/bin/get_colors.sh b/bin/get_colors.sh new file mode 100644 index 0000000..64daba7 --- /dev/null +++ b/bin/get_colors.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Helper script that with variables needed for colorizing the test output + +echo_PASSED() { + echo -e "\e[32mPASSED\e[0m" +} + +echo_FAILED() { + echo -e "\e[31mFAILED\e[0m" +} + +echo_INFO() { + echo -e "\e[33m${1}\e[0m" +} diff --git a/bin/test_nginx.sh b/bin/test_nginx.sh index 2f9de86..133eed5 100755 --- a/bin/test_nginx.sh +++ b/bin/test_nginx.sh @@ -4,6 +4,8 @@ [[ $(whoami) == 'root' ]] || { echo 'Please run this script as root'; exit 1; } +source bin/get_colors.sh + reset_nginx() { rm -rf /etc/nginx cp -a /etc/nginx_orig /etc/nginx @@ -49,15 +51,15 @@ WEB_ROLES=( $(bin/get_roles.py | grep web_) ) for role in ${WEB_ROLES[@]}; do if grep nginx salt/role/$role.sls > /dev/null; then - echo "Testing role: $role" + echo_INFO "Testing role: $role" reset_nginx reset_ip salt-call --local -l quiet state.apply role.$role > /dev/null create_fake_certs if $(nginx -tq); then - echo 'PASSED' + echo_PASSED else - echo 'FAILED' + echo_FAILED STATUS=1 fi echo diff --git a/bin/test_show_highstate.sh b/bin/test_show_highstate.sh index 3cfa81a..99e718b 100755 --- a/bin/test_show_highstate.sh +++ b/bin/test_show_highstate.sh @@ -2,6 +2,8 @@ # Runs state.show_highstate using all localized grains' combinations +source bin/get_colors.sh + if [[ $(whoami) != 'root' ]]; then if [[ -f /usr/bin/sudo ]]; then SUDO='/usr/bin/sudo' @@ -25,7 +27,7 @@ ALL_LOCATIONS=( $(bin/get_valid_custom_grains.py) ) write_grains() { $SUDO sed -i -e "s/\(city:\).*/\1 $2/" -e "s/\(country:\).*/\1 $1/" -e "s/\(osfullname:\).*/\1 $4/" -e "s/\(osmajorrelease:\).*/\1 $5/" \ -e "s/\(osrelease_info:\).*/\1 [$5, $6]/" -e "s/\(virt_cluster:\).*/\1 $3/" -e "s/\(virtual:\).*/\1 $7/" /etc/salt/grains - echo "Grains: osfullname: $4, osmajorrelease: $5, city: $2, country: $1, virt_cluster: $3, virtual: $7" + echo_INFO "Grains: osfullname: $4, osmajorrelease: $5, city: $2, country: $1, virt_cluster: $3, virtual: $7" } for os in ${ALL_OS[@]}; do @@ -37,9 +39,9 @@ for os in ${ALL_OS[@]}; do # We ignore exit code 2 as it means that an empty file is produced # See https://github.com/saltstack/salt/issues/39172 if [[ $_STATUS -eq 0 ]] || [[ $_STATUS -eq 2 ]]; then - echo 'PASSED' + echo_PASSED else - echo 'FAILED' + echo_FAILED STATUS=1 fi echo diff --git a/bin/test_validate.sh b/bin/test_validate.sh index 7a57f8a..bc456a2 100755 --- a/bin/test_validate.sh +++ b/bin/test_validate.sh @@ -2,6 +2,8 @@ # Run various code validation/syntax checks +source bin/get_colors.sh + TESTS=( extension.sh empty_files.sh @@ -12,13 +14,14 @@ TESTS=( ) for _test in ${TESTS[@]}; do - echo "Running test_${_test}" + echo_INFO "## Running test_${_test}" if bin/test_${_test}; then - echo 'PASSED' + echo_PASSED else - echo 'FAILED' + echo_FAILED STATUS=1 fi + echo done exit $STATUS