-
Notifications
You must be signed in to change notification settings - Fork 9
/
test
executable file
·167 lines (141 loc) · 3.3 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
#!/bin/bash
cd "$(dirname "$0")"
envs=( arch
alpine
ubuntu-14.04
ubuntu-16.04
ubuntu-18.04
ubuntu-20.04
ubuntu-22.04
ubuntu-24.04 )
markdowns=( $(ls doc | sed 's/.md$//' ) )
generate_gitlab_ci() {
for e in ${envs[@]}; do
echo "$e:"
echo " image: spencertipping/ni-env-dev-$e"
echo " script:"
echo " - ./test --ci"
done
}
generate_travis_ci() {
echo "sudo: required"
echo "services:"
echo "- docker"
echo "before_install:"
for e in ${envs[@]}; do
echo "- docker pull spencertipping/ni-env-dev-$e"
done
echo "script:"
for e in ${envs[@]}; do
echo "- docker run --rm -it -v \$PWD:/data -v /var/run/docker.sock:/var/run/docker.sock spencertipping/ni-env-dev-$e ./test --travis"
done
}
if [[ $1 == '-o' ]] || [[ $1 == '--only' ]]; then
test_set=$2
shift 2
fi
build_tests() {
{
echo "#!/bin/bash"
echo cd /tmp
echo export NI_NO_MONITOR=yes
./lazytest ${test_set:-$(find doc bugs -name '*.md' | sort)}
} > dev/tests.sh
}
build_ni_stuff() {
./build
build_tests
}
image() { echo spencertipping/ni-env-dev-$1; }
test_in_docker() {
cp /data/ni /usr/bin/
cp dev/tests.sh /tmp/
/usr/bin/ni --run '$ni::self{license} = ni::rfc "dev/license-for-testing";
ni::modify_self' >/dev/null
cd /tmp
bash /tmp/tests.sh
}
default_image=ubuntu-20.04
docker_dind="-v /var/run/docker.sock:/var/run/docker.sock --privileged"
docker_magic="--security-opt=seccomp=unconfined"
docker_opts="$docker_magic $docker_dind -m 256M --rm -v $PWD:/data:ro"
c=$1
shift
case $c in
-b|--build)
for e in ${envs[@]}; do
echo
echo "BUILDING $e"
echo
docker build -f env/$e -t spencertipping/ni-env-dev-$e . || exit $?
done
;;
--push)
for e in ${envs[@]}; do
docker push spencertipping/ni-env-dev-$e
done
;;
-p|--pull)
for e in ${envs[@]}; do
docker pull spencertipping/ni-env-dev-$e
done
;;
-q|--quick)
echo "NOTE: standard error is redirected into test.log"
build_ni_stuff
rm -f .test-cancel
docker run $docker_opts --name ni-test $(image ${1:-$default_image}) \
/data/test --ci 2>test.log
;;
-r|--repl)
echo "NOTE: to run tests:"
echo " $ cd /tmp"
echo " $ cp /data/ni /usr/bin/"
echo " $ bash /data/dev/tests.sh"
echo
build_ni_stuff
docker run $docker_opts -it --name ni-test-repl $(image ${1:-$default_image}) /bin/bash
;;
-c|--cancel)
touch .test-cancel
docker rm -f ni-test ni-test-hadoop
for e in ${envs[@]}; do
docker rm -f ni-test-$e ni-test-hadoop-$e
done
;;
--travis|--ci)
test_in_docker || exit $?
;;
--parallel)
echo 'NOTE: standard error is redirected into test-*.log'
build_ni_stuff
for e in ${envs[@]}; do
docker run $docker_opts \
-e ENV_SUFFIX=-$e \
--name ni-test-$e $(image $e) /data/test --ci \
2>test-$e.log &
done
wait
;;
--full)
echo "NOTE: standard error is redirected into test.log"
build_ni_stuff
rm -f .test-cancel
for e in ${envs[@]}; do
if [[ -e .test-cancel ]]; then
rm .test-cancel
exit 1
fi
echo
echo "TESTING $e"
echo
docker run $docker_opts --name ni-test $(image $e) /data/test --ci
echo
done 2>test.log
;;
--update|*)
build_tests
generate_gitlab_ci > .gitlab-ci.yml
generate_travis_ci > .travis.yml
;;
esac