-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest
executable file
·291 lines (245 loc) · 6.6 KB
/
test
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/bin/bash
set -e
set -x
export path_test="./tmp-test"
export TEST_MODE="${TEST_MODE:-full}"
export REUSE_EXISTING_WORKSPACE="${REUSE_EXISTING_WORKSPACE:-no}"
export TEARDOWN_ENVIRONMENT="${TEARDOWN_ENVIRONMENT:-yes}"
function main()
{
local harness="$1"
local mode="$2"
local sync="${3:-}"
local akeneo_version
local drupal_version
local sync_path=""
if [[ -n "$sync" ]]; then
sync_path="-${sync}"
fi
export path_test="./tmp-test-${harness}-${mode}${sync_path}"
if [[ "$TEARDOWN_ENVIRONMENT" == "yes" ]]; then
trap 'clean' EXIT
fi
if [[ "$mode" == "static" ]]; then
export MY127WS_ENV=pipeline
fi
if [[ "$harness" =~ ^(akeneo5)$ ]]; then
akeneo_version=5
harness="akeneo"
elif [[ "$harness" =~ ^(akeneo6)$ ]]; then
akeneo_version=6
harness="akeneo"
elif [[ "$harness" =~ ^(akeneo7)$ ]]; then
akeneo_version=7
harness="akeneo"
fi
if [[ "$harness" =~ ^(drupal10)$ ]]; then
drupal_version=10
harness="drupal"
elif [[ "$harness" =~ ^(drupal9)$ ]]; then
drupal_version=9
harness="drupal"
elif [[ "$harness" =~ ^(drupal8)$ ]]; then
drupal_version=8
harness="drupal"
fi
if [[ "$REUSE_EXISTING_WORKSPACE" != "yes" ]]; then
# Test default mode of static or dynamic harnesses
# For dynamic this means a mountpoint for the application code
# or mutagen
setup "$harness" "$mode"
if [[ "$sync" == "" ]]; then
setup_dynamic_mountpoint
elif [[ "$sync" == "mutagen" ]]; then
setup_dynamic_mutagen
fi
if [ -n "${akeneo_version:-}" ]; then
setup_akeneo_version "$akeneo_version"
fi
if [ -n "${drupal_version:-}" ]; then
setup_drupal_version "$drupal_version"
fi
prepare_environment
fi
if [[ "$TEST_MODE" == "quality" || "$TEST_MODE" == "full" ]]; then
test_harness_quality "$harness" "$mode" "$sync"
fi
if [[ "$TEST_MODE" == "acceptance" || "$TEST_MODE" == "full" ]]; then
test_harness_acceptance "$harness" "$mode" "$sync"
fi
if [[ "$TEARDOWN_ENVIRONMENT" == "yes" ]]; then
teardown
fi
}
function test_harness_quality()
{
local harness="$1"
local mode="$2"
local sync="$3"
./quality "${path_test}/.my127ws"
}
function test_harness_acceptance()
(
local harness="$1"
local mode="$2"
local sync="$3"
if ! [[ "$harness" =~ ^(magento1)$ ]]; then
install_console
run_project_quality_tests "$harness"
fi
install_environment
check_environment_started "$harness" "$mode"
run_project_acceptance_tests "$harness"
restart_environment
check_environment_started "$harness" "$mode"
if [[ "$sync" != "" ]]; then
wait_for_vendor_directory
fi
)
function setup()
(
local harness="$1"
local mode="$2"
local path_harness="./dist/harness-${harness}"
if [ -d "${path_test}" ]; then
rm -rf "${path_test}"
fi
cp -ap "${path_harness}/.ci/sample-${mode}" "${path_test}"
# download parent harness layers
pushd "${path_test}" >/dev/null
ws harness download
popd >/dev/null
rsync --archive "${path_harness}/" "${path_test}/.my127ws/"
)
function prepare_environment()
(
cd "${path_test}"
if [ -e init.sh ]; then
bash -x ./init.sh
fi
ws harness prepare
)
function install_console()
(
cd "${path_test}"
ws enable console
)
function install_environment()
(
cd "${path_test}"
ws install
)
function check_environment_started()
(
local harness="$1"
local mode="$2"
cd "${path_test}"
project="ci-${harness}-sample-${mode}"
if [[ "$mode" == "static" ]]; then
project="$(git log -n 1 --pretty=format:'%H')"
fi
if [ "$(docker compose -p "$project" ps | grep -v "lighthouse" | grep -c Exit)" -gt 0 ]; then
echo 'Some containers failed to start'
docker compose -p "$project" ps
return 1
fi
)
function run_project_quality_tests()
(
local harness="$1"
cd "${path_test}"
ws helm kubeval --cleanup app
# Check if we have a composer.json so we can run tests
# Check inside the console container as static builds do not
# update the local filesystem
if ws exec stat /app/composer.json > /dev/null 2>&1; then
# Run checks that don't reqiure development dependencies
ws exec composer test-production-quality
# Bring in dev dependencies
ws exec app composer:development_dependencies
# Run the tests
ws exec composer test-quality
if [[ "${harness}" != "drupal" ]]; then
ws exec composer test-unit
fi
fi
)
function run_project_acceptance_tests()
(
local harness="$1"
if [[ "$harness" =~ ^(magento1)$ ]]; then
run_project_quality_tests "$harness"
fi
cd "${path_test}"
# Check if we have a composer.json so we can run tests
# Check inside the console container as static builds do not
# update the local filesystem
if ws exec stat /app/composer.json > /dev/null 2>&1; then
ws exec composer test-acceptance
fi
if [[ "${harness}" == "drupal" ]]; then
ws test-unit
fi
ws lighthouse
)
function restart_environment()
(
cd "${path_test}"
ws disable
ws enable
)
function setup_dynamic_mountpoint()
(
cd "${path_test}"
echo "attribute('host.os'): linux" > workspace.override.yml
)
function setup_dynamic_mutagen()
(
cd "${path_test}"
echo "attribute('host.os'): darwin" > workspace.override.yml
echo "attribute('mutagen'): yes" >> workspace.override.yml
)
function setup_akeneo_version() {
local version="$1"
echo "attribute('akeneo.major_version'): ${version}" >> "${path_test}/workspace.override.yml"
}
function setup_drupal_version() {
local version="$1"
echo "attribute('drupal.major_version'): ${version}" >> "${path_test}/workspace.override.yml"
}
function wait_for_vendor_directory()
(
set +x
cd "${path_test}"
if [ ! -f composer.json ]; then
return 0
fi
local timer=600
while [ $timer -gt 0 ]; do
if [ -d vendor ]; then
echo "Found vendor directory, sync worked"
return 0
fi
timer=$(( timer - 1 ))
sleep 1
done
echo "vendor directory not found within 600 seconds, sync failed"
ls -la
return 1
)
function teardown()
(
cd "${path_test}"
ws destroy || (docker ps -a && return 1)
rm -rf .my127ws
)
function clean()
{
if [ -d "$path_test" ]; then
if [ -d "${path_test}/.my127ws" ]; then
(cd "$path_test" && ws destroy) || (docker ps -a && return 1)
fi
rm -rf "$path_test"
fi
}
main "$@"