2015-04-17 13:06:47 +10:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Tests for DevStack meta-config functions
|
|
|
|
|
|
|
|
TOP=$(cd $(dirname "$0")/.. && pwd)
|
|
|
|
|
|
|
|
# Import common functions
|
|
|
|
source $TOP/functions
|
|
|
|
source $TOP/tests/unittest.sh
|
|
|
|
|
2015-08-25 14:29:08 +10:00
|
|
|
# common mistake is to use $FOO instead of "FOO"; in that case we
|
|
|
|
# should die
|
|
|
|
bash -c "source $TOP/functions-common; VAR=\$(trueorfalse False \$FOO)" &> /dev/null
|
|
|
|
assert_equal 1 $? "missing test-value"
|
|
|
|
|
|
|
|
VAL=$(trueorfalse False MISSING_VARIABLE)
|
|
|
|
assert_equal "False" $VAL "blank test-value"
|
|
|
|
|
2015-05-11 18:02:34 +09:00
|
|
|
function test_trueorfalse {
|
2015-04-17 13:06:47 +10:00
|
|
|
local one=1
|
|
|
|
local captrue=True
|
|
|
|
local lowtrue=true
|
2015-05-11 18:02:34 +09:00
|
|
|
local uppertrue=TRUE
|
|
|
|
local capyes=Yes
|
|
|
|
local lowyes=yes
|
|
|
|
local upperyes=YES
|
|
|
|
|
|
|
|
for default in True False; do
|
|
|
|
for name in one captrue lowtrue uppertrue capyes lowyes upperyes; do
|
2015-05-25 11:29:48 +10:00
|
|
|
local msg="trueorfalse($default $name)"
|
|
|
|
assert_equal "True" $(trueorfalse $default $name) "$msg"
|
2015-05-11 18:02:34 +09:00
|
|
|
done
|
|
|
|
done
|
|
|
|
|
2015-04-17 13:06:47 +10:00
|
|
|
local zero=0
|
|
|
|
local capfalse=False
|
|
|
|
local lowfalse=false
|
2015-05-11 18:02:34 +09:00
|
|
|
local upperfalse=FALSE
|
|
|
|
local capno=No
|
|
|
|
local lowno=no
|
|
|
|
local upperno=NO
|
|
|
|
|
|
|
|
for default in True False; do
|
|
|
|
for name in zero capfalse lowfalse upperfalse capno lowno upperno; do
|
2015-05-25 11:29:48 +10:00
|
|
|
local msg="trueorfalse($default $name)"
|
|
|
|
assert_equal "False" $(trueorfalse $default $name) "$msg"
|
2015-04-17 13:06:47 +10:00
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2015-05-11 18:02:34 +09:00
|
|
|
test_trueorfalse
|
2015-04-17 13:06:47 +10:00
|
|
|
|
|
|
|
report_results
|