Skip to content

Commit f981b9f

Browse files
committed
adding prop2env
1 parent e2e2818 commit f981b9f

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

devel/java_env.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# this java property file contains the testdata
2+
# above, below and this line are comments
3+
# following lines contain testdata
4+
td_key_empty=
5+
td_key_value=td_value_string
6+
7+
# following property tuples(key/value pairs) are critical cases
8+
td_bash_special_backtick=`
9+
td_bash_specical=~$&*()\|[]{};'"<>/?!#

devel/test_prop2env.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
#
3+
#
4+
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-.}" )" &> /dev/null && pwd )
5+
6+
# test for variable existence and output value if found
7+
test_env_var_existence() {
8+
declare envvar_name=$1
9+
if [[ ! -v ${envvar_name} ]]; then
10+
echo "env var is not set"
11+
elif [[ -z "${envvar_name}" ]]; then
12+
echo "env var is set to the empty string"
13+
else
14+
echo "env var ${envvar_name}=${!envvar_name}"
15+
fi
16+
17+
# echo -ne "checking env variable for $envvar_name ... "
18+
# if [ -n "${!envvar_name}" ]; then
19+
# echo "found env var $envvar_name=${!envvar_name}"
20+
# else
21+
# echo "missing prop $envvar_name" && exit 1
22+
# fi
23+
}
24+
25+
test_env_var() {
26+
declare envvar_name="$1"
27+
declare value="$2"
28+
test_env_var_existence "${envvar_name}"
29+
if [[ ${value} == ${!envvar_name} ]]; then
30+
echo "found env var ${envvar_name}=${!envvar_name}"
31+
else
32+
echo "env <${envvar_name}>=<${!value}> is not expected value <$value>" && exit 1
33+
fi
34+
}
35+
36+
. ${script_dir}/../.klibio/prop2env.sh ${script_dir}/testdata/java_env.properties
37+
38+
test_env_var_existence td_key_empty
39+
test_env_var td_key_value td_value_string

0 commit comments

Comments
 (0)