@@ -3,6 +3,13 @@ set -eu -o pipefail
3
3
4
4
scriptdir=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
5
5
6
+ cleanup_cmd=" "
7
+ trap ' eval ${cleanup_cmd}' EXIT
8
+ function defer {
9
+ [ -n " ${cleanup_cmd} " ] && cleanup_cmd=" ${cleanup_cmd} ; "
10
+ cleanup_cmd=" ${cleanup_cmd} $1 "
11
+ }
12
+
6
13
function INFO() {
7
14
echo " TEST| [INFO] $* "
8
15
}
66
73
if [[ -n ${CHECKS["port-forwards"]} ]]; then
67
74
tmpconfig=" $HOME /lima-config-tmp"
68
75
mkdir -p " ${tmpconfig} "
69
- trap ' rm -rf $tmpconfig' EXIT
76
+ defer " rm -rf \" $tmpconfig \" "
70
77
tmpfile=" ${tmpconfig} /${NAME} .yaml"
71
78
cp " $FILE " " ${tmpfile} "
72
79
FILE=" ${tmpfile} "
@@ -86,7 +93,7 @@ function diagnose() {
86
93
}
87
94
88
95
INFO " Starting \" $NAME \" from \" $FILE \" "
89
- trap ' limactl delete -f $NAME' EXIT
96
+ defer " limactl delete -f \" $NAME \" "
90
97
set -x
91
98
if ! limactl start --tty=false " $FILE " ; then
92
99
ERROR " Failed to start \" $NAME \" "
@@ -103,7 +110,7 @@ INFO "Testing limactl copy command"
103
110
tmpfile=" $HOME /lima-hostname"
104
111
rm -f " $tmpfile "
105
112
limactl cp " $NAME " :/etc/hostname " $tmpfile "
106
- trap ' rm -f $tmpfile' EXIT
113
+ defer " rm -f \" $tmpfile \" "
107
114
expected=" $( limactl shell " $NAME " cat /etc/hostname) "
108
115
got=" $( cat " $tmpfile " ) "
109
116
INFO " /etc/hostname: expected=${expected} , got=${got} "
@@ -131,7 +138,7 @@ if [[ -n ${CHECKS["mount-home"]} ]]; then
131
138
INFO " Testing home access (\" $hometmp \" )"
132
139
rm -rf " $hometmp "
133
140
mkdir -p " $hometmp "
134
- trap ' rm -rf $hometmp' EXIT
141
+ defer " rm -rf \" $hometmp \" "
135
142
echo " random-content-${RANDOM} " > " $hometmp /random"
136
143
expected=" $( cat " $hometmp /random" ) "
137
144
got=" $( limactl shell " $NAME " cat " $hometmp /random" ) "
0 commit comments