-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·241 lines (199 loc) · 5.16 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
#!/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 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 [[ "$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
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_node_modules_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 package.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/package.json > /dev/null 2>&1; then
# Run the tests
ws exec npm run lint
ws exec npm run test:unit
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 package.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/package.json > /dev/null 2>&1; then
ws exec npm run test:acceptance
fi
)
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 wait_for_node_modules_directory()
(
set +x
cd "${path_test}"
if [ ! -f package.json ]; then
return 0
fi
local timer=600
while [ $timer -gt 0 ]; do
if [ -d node_modules ]; then
echo "Found node_modules directory, sync worked"
return 0
fi
timer=$(( timer - 1 ))
sleep 1
done
echo "node_modules 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 "$@"