1+ #! /usr/bin/env bash
2+
3+ set -euo pipefail
4+
5+ unset BOOT_JAVA_COMMAND
6+ unset BOOT_JVM_OPTIONS
7+
8+ # Variables ---------------------------------------------------------
9+
10+ global_opt=" --option-from-global-boot-properties"
11+ global_cmd=" java-global"
12+ local_opt=" --option-from-local-boot-properties"
13+ local_cmd=" java-local"
14+ env_opt=" --env-option"
15+ env_cmd=" java-env"
16+
17+ headsh=" $( pwd) /src/head.sh"
18+ dir=" $( mktemp -q -d) "
19+
20+ error=" "
21+
22+ # Setup -------------------------------------------------------------
23+
24+ mkdir " $dir /.boot"
25+ export BOOT_HOME=" $dir /.boot"
26+
27+ pushd " $dir " > /dev/null
28+
29+ echo " Testing in directory $dir "
30+ # echo "BOOT_HOME = $BOOT_HOME\n"
31+
32+ # Prepare modified version of `head.sh`
33+ # that just prints java command and options
34+
35+ sed ' $ d' " $headsh " > " $dir /head.sh"
36+ echo ' echo "$java_command" "${options[@]-}"' >> " $dir /head.sh"
37+ chmod +x " $dir /head.sh"
38+
39+ # Helpers -----------------------------------------------------------
40+
41+ test_head_sh () {
42+ out=" $( " $dir /head.sh" ) "
43+ if [ " $out " == " $1 " ]; then
44+ echo " ✅ $out "
45+ else
46+ echo " EXPECTED: $1 "
47+ echo " 🛑 WAS: $out "
48+ error=" yes"
49+ # exit 1
50+ fi
51+ }
52+
53+ write_global () {
54+ printf " BOOT_JAVA_COMMAND=$global_cmd \nBOOT_JVM_OPTIONS=$global_opt \n" > " $BOOT_HOME /boot.properties"
55+ }
56+ clean_global () {
57+ rm " $dir /.boot/boot.properties"
58+ }
59+ write_local () {
60+ # missing newline at the end here is no mistake :)
61+ printf " BOOT_JAVA_COMMAND=$local_cmd \nBOOT_JVM_OPTIONS=$local_opt " > " $dir /boot.properties"
62+ }
63+ clean_local () {
64+ rm " $dir /boot.properties"
65+ }
66+ set_env () {
67+ export BOOT_JAVA_COMMAND=$env_cmd
68+ export BOOT_JVM_OPTIONS=$env_opt
69+ }
70+ clean_env () {
71+ unset BOOT_JAVA_COMMAND
72+ unset BOOT_JVM_OPTIONS
73+ }
74+
75+ # Test setting of global options ------------------------------------
76+
77+ printf " \nTesting \$ BOOT_HOME/boot.properties\n"
78+
79+ write_global
80+ test_head_sh " $global_cmd $global_opt "
81+ clean_global
82+
83+ # Test setting of local options -------------------------------------
84+
85+ printf " \nTesting ./boot.properties\n"
86+
87+ write_local
88+ test_head_sh " $local_cmd $local_opt "
89+ clean_local
90+
91+ # Test local > global precedence ------------------------------------
92+
93+ printf " \nTesting local > global precedence\n"
94+
95+ write_global
96+ write_local
97+ test_head_sh " $local_cmd $local_opt "
98+ clean_global
99+ clean_local
100+
101+ # Test env > local > global precedence ------------------------------
102+
103+ printf " \nTesting env > local > global precedence\n"
104+
105+ write_global
106+ write_local
107+ set_env
108+ test_head_sh " $env_cmd $env_opt "
109+ clean_global
110+ clean_local
111+ clean_env
112+
113+ # Test mixing of env & local ----------------------------------------
114+
115+ printf " \nTesting mixing of env & local\n"
116+
117+ printf " BOOT_JAVA_COMMAND=$local_cmd \n" > " $dir /boot.properties"
118+ export BOOT_JVM_OPTIONS=$env_opt
119+ test_head_sh " $local_cmd $env_opt "
120+ clean_local
121+ clean_env
122+
123+ # Test mixing of local & global -------------------------------------
124+
125+ printf " \nTesting mixing of local & global\n"
126+
127+ printf " BOOT_JAVA_COMMAND=$local_cmd \n" > " $dir /boot.properties"
128+ printf " BOOT_JVM_OPTIONS=$global_opt \n" > " $BOOT_HOME /boot.properties"
129+ test_head_sh " $local_cmd $global_opt "
130+ clean_local
131+ clean_global
132+
133+ popd " $dir " > /dev/null
134+
135+ if [ " $error " == " yes" ]; then
136+ printf " \nSome errors occurred. 🛑\n"
137+ exit 1
138+ else
139+ rm -rf " $dir "
140+ fi
0 commit comments