This repository was archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathtest-init.sh
executable file
·260 lines (219 loc) · 6.35 KB
/
test-init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/usr/bin/env bash
# DBDeployer - The MySQL Sandbox
# Copyright © 2006-2020 Giuseppe Maxia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
fail=0
if [ -d $HOME/opt ]
then
mv $HOME/opt $HOME/noopt
if [ -d $HOME/opt ]
then
echo "not ok - error renaming $HOME/opt"
exit 1
fi
fi
function remove_completion_file {
if [ -f dbdeployer_completion.sh ]
then
rm -f dbdeployer_completion.sh
fi
}
function cleanup {
bin=$(dbdeployer info defaults sandbox-binary)
smb=$(dbdeployer info defaults sandbox-home)
dbdeployer defaults reset
if [ -d $bin ]
then
rm -rf $bin
fi
if [ -d $smb ]
then
rm -rf $smb
fi
remove_completion_file
}
function check_exit_code {
exit_code=$?
if [ "$exit_code" != "0" ]
then
echo "not ok - non-zero exit code detected ($exit_code)"
exit $exit_code
fi
}
function exists {
file_name=$1
mode=$2
def=""
case $mode in
-f)
def=file
;;
-d)
def=directory
;;
-e)
def=executable
;;
esac
if [ $mode $file_name ]
then
echo "ok - $def $file_name exists"
else
echo "not ok - $def $file_name does not exist"
fail=$((fail+1))
if [ -n "$EXIT_ON_FAILURE" ]
then
exit 1
fi
fi
}
function not_exists {
fname=$1
if [ -e $fname ]
then
echo "not ok - $fname exists"
fail=$((fail+1))
if [ -n "$EXIT_ON_FAILURE" ]
then
exit 1
fi
else
echo "ok - $fname does not exist"
fi
}
function ok_equal {
label="$1"
a="$2"
b="$3"
if [ "$a" == "$b" ]
then
echo "ok - $label - '$a'"
else
echo "not ok - $label - '$a' and '$b' are different"
fail=$((fail+1))
if [ -n "$EXIT_ON_FAILURE" ]
then
exit 1
fi
fi
}
completion_file=/etc/bash_completion.d/dbdeployer_completion.sh
if [ -f $completion_file ]
then
rm -f $completion_file
fi
dashline="# ---------------------------------------------------------"
echo $dashline
echo "# default initialization: will create binary directory and populate it"
echo $dashline
dbdeployer init
check_exit_code
exists $HOME/opt/mysql -d
exists $HOME/sandboxes -d
exists $HOME/opt/mysql/*/bin/mysqld -x
exists $completion_file -f
ok_equal "sandbox home" "$(dbdeployer info defaults sandbox-home)" "$HOME/sandboxes"
ok_equal "sandbox binary" "$(dbdeployer info defaults sandbox-binary)" "$HOME/opt/mysql"
echo $dashline
echo "# idempotent initialization 1: will check existence and do nothing"
echo $dashline
dbdeployer init
check_exit_code
export mybin=$HOME/mybin
export mysmb=$HOME/mysmb
echo $dashline
echo "# initialization with custom parameters"
echo $dashline
dbdeployer init --sandbox-home=$mysmb --sandbox-binary=$mybin
check_exit_code
exists $mybin -d
exists $mysmb -d
exists $mybin/*/bin/mysqld -x
ok_equal "sandbox home" "$(dbdeployer info defaults sandbox-home)" "$mysmb"
ok_equal "sandbox binary" "$(dbdeployer info defaults sandbox-binary)" "$mybin"
remove_completion_file
echo $dashline
echo "# idempotent initialization 2: will check existence and do nothing"
echo $dashline
dbdeployer init
check_exit_code
ok_equal "sandbox home" "$(dbdeployer info defaults sandbox-home)" "$mysmb"
ok_equal "sandbox binary" "$(dbdeployer info defaults sandbox-binary)" "$mybin"
echo $dashline
echo "# initialization with custom environmengt variables"
echo $dashline
export SANDBOX_BINARY=$HOME/mybinaries
export SANDBOX_HOME=$HOME/mysandboxes
dbdeployer init
check_exit_code
exists $SANDBOX_HOME -d
exists $SANDBOX_BINARY -d
exists $SANDBOX_BINARY/*/bin/mysqld -x
ok_equal "sandbox home" "$(dbdeployer info defaults sandbox-home)" "$SANDBOX_HOME"
ok_equal "sandbox binary" "$(dbdeployer info defaults sandbox-binary)" "$SANDBOX_BINARY"
remove_completion_file
echo $dashline
echo "# idempotent initialization 3: will check existence and do nothing"
echo $dashline
dbdeployer init
check_exit_code
ok_equal "sandbox home" "$(dbdeployer info defaults sandbox-home)" "$SANDBOX_HOME"
ok_equal "sandbox binary" "$(dbdeployer info defaults sandbox-binary)" "$SANDBOX_BINARY"
remove_completion_file
echo $dashline
echo "# dry-run initialization: will show actions and do nothing"
echo $dashline
dbdeployer init --dry-run
check_exit_code
ok_equal "sandbox home" "$(dbdeployer info defaults sandbox-home)" "$SANDBOX_HOME"
ok_equal "sandbox binary" "$(dbdeployer info defaults sandbox-binary)" "$SANDBOX_BINARY"
remove_completion_file
echo $dashline
echo "# dry-run initialization with options: will show actions and do nothing"
echo $dashline
dbdeployer init --dry-run --sandbox-home=dummy1 --sandbox-binary=dummy2
check_exit_code
exists $SANDBOX_HOME -d
exists $SANDBOX_BINARY -d
exists $SANDBOX_BINARY/*/bin/mysqld -x
ok_equal "sandbox home" "$(dbdeployer info defaults sandbox-home)" "$SANDBOX_HOME"
ok_equal "sandbox binary" "$(dbdeployer info defaults sandbox-binary)" "$SANDBOX_BINARY"
mysqld=$SANDBOX_BINARY/*/bin/mysqld
echo $dashline
echo "# initialization without downloads"
echo $dashline
cleanup
not_exists $SANDBOX_HOME
not_exists $SANDBOX_BINARY
dbdeployer init --skip-all-downloads
check_exit_code
ok_equal "sandbox home" "$(dbdeployer info defaults sandbox-home)" "$SANDBOX_HOME"
ok_equal "sandbox binary" "$(dbdeployer info defaults sandbox-binary)" "$SANDBOX_BINARY"
not_exists $mysqld
remove_completion_file
echo $dashline
echo "# initialization without tarball download"
echo $dashline
cleanup
not_exists $SANDBOX_HOME
not_exists $SANDBOX_BINARY
dbdeployer init --skip-tarball-download
check_exit_code
ok_equal "sandbox home" "$(dbdeployer info defaults sandbox-home)" "$SANDBOX_HOME"
ok_equal "sandbox binary" "$(dbdeployer info defaults sandbox-binary)" "$SANDBOX_BINARY"
not_exists $mysqld
if [ "$fail" != "0" ]
then
exit 1
fi