-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest
executable file
·198 lines (167 loc) · 4.14 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
#!/bin/bash
set -e
set -x
export path_test="./tmp-test"
function main()
{
test "$1" "$2" "${3:-}"
}
function test()
(
local harness="$1"
local mode="$2"
local sync="$3"
if [[ "$mode" == "static" ]]; then
export MY127WS_ENV=pipeline
fi
# 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 ! [[ "$harness" =~ ^(magento1)$ ]]; then
install_console
run_isolated_tests "$harness"
fi
install_environment
check_environment_started "$harness" "$mode"
run_pipeline_tests "$harness"
restart_environment
check_environment_started "$harness" "$mode"
if [[ "$sync" != "" ]]; then
wait_for_vendor_directory
fi
teardown
)
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}"
cp -ap "${path_harness}" "${path_test}/.my127ws"
)
function install_console()
(
cd "${path_test}"
ws harness download
ws harness prepare
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_isolated_tests()
(
local harness="$1"
cd "${path_test}"
ws helm kubeval --cleanup qa
# 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}" != "drupal8" ]]; then
ws exec composer test-unit
fi
fi
)
function run_pipeline_tests()
(
local harness="$1"
if [[ "$harness" =~ ^(magento1)$ ]]; then
run_isolated_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}" == "drupal8" ]]; 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 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
(cd "$path_test" && ws destroy) || (docker ps -a && return 1)
rm -rf "$path_test"
fi
}
trap 'clean' EXIT
main "$@"