Skip to content

Commit

Permalink
Fix bash testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
enxebre committed Jul 13, 2015
1 parent 9cc75d3 commit f071ba2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
6 changes: 5 additions & 1 deletion bootstrap/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ verify_prereqs() {

check_terraform_version() {
local IFS='.'
local current_version_string=$(terraform --version | awk 'NR==1 {print $2}')
if [ -z "$2" ]; then
local current_version_string=$(terraform --version | awk 'NR==1 {print $2}')
else
local current_version_string="$2"
fi
local requirement_version_string=${1:-0.5.0}
local -a current_version=( ${current_version_string#'v'} )
local -a requirement_version=( ${requirement_version_string} )
Expand Down
21 changes: 11 additions & 10 deletions bootstrap/tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@ source ../common.sh

RED='\033[0;31m'
NC='\033[0m'
FAIL=0

test() {
function="$1"
expected="$2"
input="$3"

result=$( "${function}" "${input}" )
[ $? -eq 0 ] || echo "Function ${function} returned exit code 0."
result=$( "$1" ${*:3} )

if [ "${result}" == "${expected}" ]; then
echo "Pass. Function ${function}. Expected: ${expected}, Got: ${result}"
echo -e "Pass. Function ${function}. Expected: ${expected}, Got: ${result}\n"
else
echo "${RED}Fail. Function ${function}. Expected: ${expected}, Got: ${result}${NC}"
echo -e "${RED}Fail. Function ${function}. Expected: ${expected}, Got: ${result}${NC}"
FAIL=1
fi
}

function="check_terraform_version"
expected="You are running Terraform v0.5.0..."
input="0.5.0"
test "${function}" "${expected}" "${input}"
expected="You are running Terraform v0.6.0..."
test "${function}" "${expected}" '0.5.0' 'v0.6.0'

function="check_terraform_version"
expected="You are running Terraform v0.5.0...
-e Terraform >= 0.7.0 is required, please fix and retry."
Terraform >= 0.7.0 is required, please fix and retry."
input="0.7.0"
test "${function}" "${expected}" "${input}"
test "${function}" "${expected}" '0.7.0' 'v0.5.0'

export TESTSUITE_var1="Galicia"
export TESTSUITE_var2="Drupal"
Expand All @@ -50,3 +49,5 @@ function="get_network_identifier"
expected="172"
input="172.31.1.0/24"
test "${function}" "${expected}" "${input}"

exit "${FAIL}"

0 comments on commit f071ba2

Please sign in to comment.