forked from heartsucker/node-deb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·216 lines (174 loc) · 5.62 KB
/
test.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
#!/bin/bash
set -e
declare -ar all_images=('debian-stretch'
'debian-jessie'
'debian-wheezy'
'ubuntu-xenial'
'ubuntu-trusty')
# TODO wheezy doesn't have a good upstat image
declare -ar upstart_images=('ubuntu-trusty')
# TODO debian doesn't have nice images for this
declare -ar systemd_images=('ubuntu-xenial')
# TODO why doesn't this work in jessie / xenial?
declare -ar sysv_images=('debian-stretch'
'debian-wheezy'
'ubuntu-trusty')
declare -ar all_tests=('simple'
'whitespace'
'node-deb-override'
'commandline-override'
'extra-files'
'no-init'
'no-default-dependencies'
'real-app'
'real-cli')
declare -ar simple_tests=('dog-food'
'npm-install')
print_yellow() {
printf "\033[33;1m%s\033[0m\n\n" "$*"
}
print_green() {
printf "\033[32;1m%s\033[0m\n\n" "$*"
}
print_divider() {
printf "\033[34;1m--------------------------------------------\033[0m\n"
}
usage() {
# Local var because of grep
declare helpdoc='HELP'
helpdoc+='DOC'
echo 'Usage: test.sh [opts]'
echo 'Opts:'
grep "$helpdoc" "$0" -B 1 | egrep -v '^--$' | sed -e 's/^ //g' -e "s/# $helpdoc: //g"
}
while [ -n "$1" ]; do
param="$1"
value="$2"
case $param in
--distribution | -d)
# HELPDOC: The distro to test. Blank == all.
distro="$value"
shift
;;
--help | -h)
# HELPDOC: Print this message then exit.
usage
exit 0
;;
--test | -t)
# HELPDOC: The test to run. Blank == all.
test_name="$value"
shift
;;
*)
echo "Unnown argument: $param"
usage
exit 1
;;
esac
shift
done
# if we're in TravisCI land, and we've updated the docker images then rebuild them so the tests match
if [ -n "$TRAVIS_BRANCH" ]; then
# we have to fetch because travis pulls the current branch only by default
declare build_head=$(git rev-parse HEAD)
git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
git fetch
git checkout -qf develop
git checkout "$build_head"
if [ -n "$(git diff --name-only develop -- docker)" ]; then
./docker/docker.sh
fi
fi
fail() {
printf '\n\033[31;1mTest failed!\033[0m\n\n'
}
trap 'fail' EXIT
for tst in "${all_tests[@]}"; do
if [[ "$tst" != "${test_name:-$tst}" ]]; then continue; fi
for image in "${all_images[@]}"; do
if [[ "$image" != "${distro:-$image}" ]]; then continue; fi
print_yellow "Running test $tst for image $image"
docker run --rm \
--volume "$PWD:/src" \
--workdir '/src' \
"heartsucker/node-deb-test:$image" \
"/src/test/$tst/test.sh"
print_green "Success for test $tst for image $image"
print_divider
done
done
for image in "${systemd_images[@]}"; do
if [[ 'systemd' != "${test_name:-systemd}" ]]; then continue; fi
if [[ "$image" != "${distro:-$image}" ]]; then continue; fi
print_yellow "Running systemd test for image $image"
name="$image-node-deb"
docker rm -f "$name" || echo 'container not removed'
docker run --volume "$PWD:/src" \
--workdir '/src' \
--name "$name" \
--detach \
--privileged \
--volume /:/host \
"heartsucker/node-deb-test:$image" \
'/sbin/init'
docker start "$name"
docker exec "$name" \
'/src/test/systemd-app/test.sh'
docker rm -f "$name"
# TODO add trap that kills the container
print_green "Success for systemd test for image $image"
print_divider
done
for image in "${upstart_images[@]}"; do
if [[ 'upstart' != "${test_name:-'upstart'}" ]]; then continue; fi
if [[ "$image" != "${distro:-$image}" ]]; then continue; fi
print_yellow "Running upstart test for image $image"
name="$image-node-deb"
docker rm -f "$name" || echo 'container not removed'
docker run --volume "$PWD:/src" \
--workdir '/src' \
--name "$name" \
--detach \
"heartsucker/node-deb-test:$image" \
'/sbin/init'
docker start "$name"
docker exec "$name" \
'/src/test/upstart-app/test.sh'
docker rm -f "$name"
# TODO add trap that kills the container
print_green "Success for upstart test for image $image"
print_divider
done
for image in "${sysv_images[@]}"; do
if [[ 'sysv' != "${test_name:-sysv}" ]]; then continue; fi
if [[ "$image" != "${distro:-$image}" ]]; then continue; fi
print_yellow "Running sysv test for image $image"
name="$image-node-deb"
docker run --rm \
--volume "$PWD:/src" \
--workdir '/src' \
--name "$name" \
"heartsucker/node-deb-test:$image" \
'/src/test/sysv-app/test.sh'
print_green "Success for sysv test for image $image"
print_divider
done
for tst in "${simple_tests[@]}"; do
if [[ "$tst" != "${test_name:-$tst}" ]]; then continue; fi
for image in "${all_images[@]}"; do
if [[ "$image" != "${distro:-$image}" ]]; then continue; fi
print_yellow "Running simple test $tst for image $image"
docker run --rm \
--volume "$PWD:/src" \
--workdir '/src' \
"heartsucker/node-deb-test:$image" \
"/src/test/$tst.sh"
print_green "Success for test $tst for image $image"
print_divider
done
done
# clear the trap so we don't print the fail message
trap - EXIT
trap
print_green 'Success!'