Skip to content

Commit 848dc35

Browse files
authored
Merge pull request #7888 from infosiftr/windows-tests
Adjust test harness to run many tests successfully on Windows
2 parents ca4013a + f8c09a0 commit 848dc35

File tree

14 files changed

+237
-124
lines changed

14 files changed

+237
-124
lines changed

test/clean.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
#!/bin/bash
2-
set -e
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
33

4-
docker images 'librarytest/*' | awk 'NR>1 { print $1":"$2 }' | xargs -r docker rmi
4+
docker image ls --digests --no-trunc --format '
5+
{{- if ne .Tag "<none>" -}}
6+
{{- .Repository -}} : {{- .Tag -}}
7+
{{- else if ne .Digest "<none>" -}}
8+
{{- .Repository -}} @ {{- .Digest -}}
9+
{{- else -}}
10+
{{- .ID -}}
11+
{{- end -}}
12+
' 'librarytest/*' | xargs -rt docker image rm

test/config.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ globalTests+=(
1111
# for "explicit" images, only run tests that are explicitly specified for that image/variant
1212
explicitTests+=(
1313
[:onbuild]=1
14-
[:nanoserver]=1
15-
[:windowsservercore]=1
1614
)
1715
imageTests[:onbuild]+='
1816
override-cmd
@@ -272,6 +270,14 @@ globalExcludeTests+=(
272270
[swarm_utc]=1
273271
[traefik_utc]=1
274272

273+
# windows!
274+
[:nanoserver_cve-2014--shellshock]=1
275+
[:nanoserver_no-hard-coded-passwords]=1
276+
[:nanoserver_utc]=1
277+
[:windowsservercore_cve-2014--shellshock]=1
278+
[:windowsservercore_no-hard-coded-passwords]=1
279+
[:windowsservercore_utc]=1
280+
275281
[hello-world_no-hard-coded-passwords]=1
276282
[nats_no-hard-coded-passwords]=1
277283
[nats-streaming_no-hard-coded-passwords]=1
@@ -282,9 +288,10 @@ globalExcludeTests+=(
282288
# https://github.com/docker-library/official-images/pull/1721#issuecomment-234128477
283289
[clearlinux_no-hard-coded-passwords]=1
284290

285-
# alpine/slim openjdk images are headless and so can't do font stuff
291+
# alpine/slim/nanoserver openjdk images are headless and so can't do font stuff
286292
[openjdk:alpine_java-uimanager-font]=1
287293
[openjdk:slim_java-uimanager-font]=1
294+
[openjdk:nanoserver_java-uimanager-font]=1
288295
# and adoptopenjdk has opted not to
289296
[adoptopenjdk_java-uimanager-font]=1
290297

@@ -299,4 +306,10 @@ globalExcludeTests+=(
299306
# the Swift slim images are not expected to be able to run the swift-hello-world test because it involves compiling Swift code. The slim images are for running an already built binary.
300307
# https://github.com/docker-library/official-images/pull/6302#issuecomment-512181863
301308
[swift:slim_swift-hello-world]=1
309+
310+
# TODO adjust MongoDB tests to use docker networks instead of links so they can work on Windows (and consider using PowerShell to generate appropriate certificates for TLS tests instead of openssl)
311+
[mongo:windowsservercore_mongo-basics]=1
312+
[mongo:windowsservercore_mongo-auth-basics]=1
313+
[mongo:windowsservercore_mongo-tls-basics]=1
314+
[mongo:windowsservercore_mongo-tls-auth]=1
302315
)

test/run.sh

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#!/bin/bash
2-
set -e
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
33

44
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
55

@@ -46,7 +46,7 @@ while true; do
4646
esac
4747
done
4848

49-
if [ $# -eq 0 ]; then
49+
if [ "$#" -eq 0 ]; then
5050
usage >&2
5151
exit 1
5252
fi
@@ -59,10 +59,21 @@ declare -A globalExcludeTests=()
5959
declare -A explicitTests=()
6060

6161
# if there are no user-specified configs, use the default config
62-
if [ ${#configs} -eq 0 ]; then
63-
configs+=("$dir/config.sh")
62+
if [ "${#configs[@]}" -eq 0 ]; then
63+
configs+=( "$dir/config.sh" )
6464
fi
6565

66+
case "$(uname -o)" in
67+
Msys)
68+
# https://stackoverflow.com/a/34386471/433558
69+
# https://github.com/docker/toolbox/blob/6960f28d5b01857d69b2095a02949264f09d3e57/windows/start.sh#L104-L107
70+
docker() {
71+
MSYS_NO_PATHCONV=1 command docker "$@"
72+
}
73+
export -f docker
74+
;;
75+
esac
76+
6677
# load the configs
6778
declare -A testPaths=()
6879
for conf in "${configs[@]}"; do
@@ -72,7 +83,7 @@ for conf in "${configs[@]}"; do
7283
confDir="$(dirname "$conf")"
7384

7485
for testName in ${globalTests[@]} ${imageTests[@]}; do
75-
[ "${testPaths[$testName]}" ] && continue
86+
[ -n "${testPaths[$testName]:-}" ] && continue
7687

7788
if [ -d "$confDir/tests/$testName" ]; then
7889
# Test directory found relative to the conf file
@@ -116,11 +127,11 @@ for dockerImage in "$@"; do
116127
variant='psmdb'
117128
;;
118129
*nanoserver*)
119-
# all nanoserver variants are windows and should have explict tests
130+
# all nanoserver variants are windows
120131
variant='nanoserver'
121132
;;
122133
*windowsservercore*)
123-
# all servercore variants are windows and should have explict tests
134+
# all servercore variants are windows
124135
variant='windowsservercore'
125136
;;
126137
esac
@@ -131,10 +142,10 @@ for dockerImage in "$@"; do
131142
fi
132143

133144
for possibleAlias in \
134-
"${testAlias[$repo:$variant]}" \
135-
"${testAlias[$repo]}" \
136-
"${testAlias[$testRepo:$variant]}" \
137-
"${testAlias[$testRepo]}" \
145+
"${testAlias[$repo:$variant]:-}" \
146+
"${testAlias[$repo]:-}" \
147+
"${testAlias[$testRepo:$variant]:-}" \
148+
"${testAlias[$testRepo]:-}" \
138149
; do
139150
if [ -n "$possibleAlias" ]; then
140151
testRepo="$possibleAlias"
@@ -144,9 +155,9 @@ for dockerImage in "$@"; do
144155

145156
explicitVariant=
146157
if [ \
147-
"${explicitTests[:$variant]}" \
148-
-o "${explicitTests[$repo:$variant]}" \
149-
-o "${explicitTests[$testRepo:$variant]}" \
158+
"${explicitTests[:$variant]:-}" \
159+
-o "${explicitTests[$repo:$variant]:-}" \
160+
-o "${explicitTests[$testRepo:$variant]:-}" \
150161
]; then
151162
explicitVariant=1
152163
fi
@@ -156,41 +167,41 @@ for dockerImage in "$@"; do
156167
testCandidates+=( "${globalTests[@]}" )
157168
fi
158169
testCandidates+=(
159-
${imageTests[:$variant]}
170+
${imageTests[:$variant]:-}
160171
)
161172
if [ -z "$explicitVariant" ]; then
162173
testCandidates+=(
163-
${imageTests[$testRepo]}
174+
${imageTests[$testRepo]:-}
164175
)
165176
fi
166177
testCandidates+=(
167-
${imageTests[$testRepo:$variant]}
178+
${imageTests[$testRepo:$variant]:-}
168179
)
169180
if [ "$testRepo" != "$repo" ]; then
170181
if [ -z "$explicitVariant" ]; then
171182
testCandidates+=(
172-
${imageTests[$repo]}
183+
${imageTests[$repo]:-}
173184
)
174185
fi
175186
testCandidates+=(
176-
${imageTests[$repo:$variant]}
187+
${imageTests[$repo:$variant]:-}
177188
)
178189
fi
179190

180191
tests=()
181192
for t in "${testCandidates[@]}"; do
182-
if [ ${#argTests[@]} -gt 0 -a -z "${argTests[$t]}" ]; then
193+
if [ "${#argTests[@]}" -gt 0 ] && [ -z "${argTests[$t]:-}" ]; then
183194
# skipping due to -t
184195
continue
185196
fi
186197

187198
if [ \
188-
! -z "${globalExcludeTests[${testRepo}_$t]}" \
189-
-o ! -z "${globalExcludeTests[${testRepo}:${variant}_$t]}" \
190-
-o ! -z "${globalExcludeTests[:${variant}_$t]}" \
191-
-o ! -z "${globalExcludeTests[${repo}_$t]}" \
192-
-o ! -z "${globalExcludeTests[${repo}:${variant}_$t]}" \
193-
-o ! -z "${globalExcludeTests[:${variant}_$t]}" \
199+
! -z "${globalExcludeTests[${testRepo}_$t]:-}" \
200+
-o ! -z "${globalExcludeTests[${testRepo}:${variant}_$t]:-}" \
201+
-o ! -z "${globalExcludeTests[:${variant}_$t]:-}" \
202+
-o ! -z "${globalExcludeTests[${repo}_$t]:-}" \
203+
-o ! -z "${globalExcludeTests[${repo}:${variant}_$t]:-}" \
204+
-o ! -z "${globalExcludeTests[:${variant}_$t]:-}" \
194205
]; then
195206
# skipping due to exclude
196207
continue
@@ -223,10 +234,11 @@ for dockerImage in "$@"; do
223234
scriptDir="${testPaths[$t]}"
224235
if [ -d "$scriptDir" ]; then
225236
script="$scriptDir/run.sh"
226-
if [ -x "$script" -a ! -d "$script" ]; then
237+
if [ -x "$script" ] && [ ! -d "$script" ]; then
227238
# TODO dryRun logic
228-
if output="$("$script" $dockerImage)"; then
229-
if [ -f "$scriptDir/expected-std-out.txt" ] && ! d="$(echo "$output" | diff -u "$scriptDir/expected-std-out.txt" - 2>/dev/null)"; then
239+
if output="$("$script" "$dockerImage")"; then
240+
output="$(tr -d '\r' <<<"$output")" # Windows gives us \r\n ... :D
241+
if [ -f "$scriptDir/expected-std-out.txt" ] && ! d="$(diff -u "$scriptDir/expected-std-out.txt" - <<<"$output" 2>/dev/null)"; then
230242
echo 'failed; unexpected output:'
231243
echo "$d"
232244
didFail=1
@@ -252,6 +264,6 @@ for dockerImage in "$@"; do
252264
done
253265
done
254266

255-
if [ "$didFail" ]; then
267+
if [ -n "$didFail" ]; then
256268
exit 1
257269
fi

test/tests/docker-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ fi
3030

3131
cp -RL "$dir" "$tmp/dir"
3232

33-
docker build -t "$imageTag" "$tmp" > /dev/null
33+
command docker build -t "$imageTag" "$tmp" > /dev/null

test/tests/hylang-sh/container.hy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44

55
(import subprocess sys)
66
(subprocess.check_call [sys.executable "-m" "pip" "install" "-q" "sh"])
7+
(import platform)
8+
9+
(comment Windows is not supported by sh (sad day))
10+
(comment https://github.com/amoffat/sh/blob/608f4c3bf5ad75ad40035d03a9c5ffcce0898f07/sh.py#L33-L36)
11+
(if (= (.system platform) "Windows")
12+
(defn echo [dashn num] (return num))
13+
(import [sh [echo]]))
714

8-
(import [sh [echo]])
915
(->
1016
(+
1117
(int (echo "-n" 21))

test/tests/mongo-basics/run.sh

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,33 @@ if docker info --format '{{ join .SecurityOptions "\n" }}' 2>/dev/null |tac|tac|
2222

2323
# need set_mempolicy syscall to be able to do numactl for mongodb
2424
# if "set_mempolicy" is not in the always allowed list, add it
25-
extraSeccomp="$(echo "$seccomp" | docker run -i --rm "$jqImage" --tab '
26-
.syscalls[] |= if (
27-
.action == "SCMP_ACT_ALLOW"
28-
and .args == []
29-
and .comment == ""
30-
and .includes == {}
31-
and .excludes == {}
32-
) then (
33-
if ( .names | index("set_mempolicy") ) > 0 then
25+
extraSeccomp="$(
26+
docker run -i --rm "$jqImage" --tab '
27+
.syscalls[] |= if (
28+
.action == "SCMP_ACT_ALLOW"
29+
and .args == []
30+
and .comment == ""
31+
and .includes == {}
32+
and .excludes == {}
33+
) then (
34+
if ( .names | index("set_mempolicy") ) > 0 then
35+
.
36+
else (
37+
.names |= . + ["set_mempolicy"]
38+
) end
39+
)
40+
else
3441
.
35-
else (
36-
.names |= . + ["set_mempolicy"]
37-
) end
38-
)
39-
else
40-
.
41-
end
42-
')"
42+
end
43+
' <<<"$seccomp"
44+
)"
4345
else
4446
echo >&2 'warning: the current Docker daemon does not appear to support seccomp'
4547
fi
4648

4749
docker_run_seccomp() {
4850
if [ "$haveSeccomp" ]; then
49-
docker run --security-opt seccomp=<(echo "$extraSeccomp") "$@"
51+
docker run --security-opt seccomp=<(cat <<<"$extraSeccomp") "$@"
5052
else
5153
docker run "$@"
5254
fi

test/tests/override-cmd/run.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#!/bin/bash
2-
set -eo pipefail
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
33

44
image="$1"
55

@@ -8,13 +8,22 @@ image="$1"
88

99
hello="world-$RANDOM-$RANDOM"
1010

11+
cmd=( echo "Hello $hello" )
12+
case "$image" in
13+
*windowsservercore* | *nanoserver*)
14+
cmd=( cmd /Q /S /C "${cmd[*]}" )
15+
;;
16+
esac
17+
1118
# test first with --entrypoint to verify that we even have echo (tests for single-binary images FROM scratch, essentially)
12-
if ! testOutput="$(docker run --rm --entrypoint echo "$image" "Hello $hello" 2>/dev/null)"; then
19+
if ! testOutput="$(docker run --rm --entrypoint "${cmd[0]}" "$image" "${cmd[@]:1}" 2>/dev/null)"; then
1320
echo >&2 'image does not appear to contain "echo" -- assuming single-binary image'
1421
exit
1522
fi
23+
testOutput="$(tr -d '\r' <<<"$testOutput")" # Windows gives us \r\n ... :D
1624
[ "$testOutput" = "Hello $hello" ]
1725

1826
# now test with normal command to verify the default entrypoint is OK
19-
output="$(docker run --rm "$image" echo "Hello $hello")"
27+
output="$(docker run --rm "$image" "${cmd[@]}")"
28+
output="$(tr -d '\r' <<<"$output")" # Windows gives us \r\n ... :D
2029
[ "$output" = "Hello $hello" ]

test/tests/python-hy/container.cmd

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@echo off
2+
3+
for %%p in ( pypy3 pypy python3 python ) do (
4+
%%p --version >nul 2>&1 && (
5+
set python=%%p
6+
goto found
7+
)
8+
)
9+
echo unable to run Hy test -- seems this image does not contain Python? >&2
10+
exit /b 1
11+
12+
:found
13+
%python% --version >nul 2>&1 || exit /b %errorlevel%
14+
15+
rem Hy is complicated, and uses Python's internal AST representation directly, and thus Hy releases usually lag behind a little on major Python releases (and we don't want that to gum up our tests)
16+
rem see https://github.com/hylang/hy/issues/1111 for example breakage
17+
%python% -c "import sys; exit((sys.version_info[0] == 3 and sys.version_info[1] >= 8) or sys.version_info[0] > 3)" || (
18+
echo skipping Hy test -- not allowed on Python 3.8+ ^(yet!^) >&2
19+
rem cheaters gunna cheat
20+
type expected-std-out.txt
21+
exit /b 0
22+
)
23+
24+
pip install -q "hy==0.17.0" || exit /b %errorlevel%
25+
26+
hy ./container.hy || exit /b %errorlevel%
27+
28+
exit /b 0

test/tests/python-hy/container.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
2-
set -e
2+
set -eu
33

44
python=
55
for c in pypy3 pypy python3 python; do
@@ -18,9 +18,11 @@ fi
1818
# see https://github.com/hylang/hy/issues/1111 for example breakage
1919
if ! "$python" -c 'import sys; exit((sys.version_info[0] == 3 and sys.version_info[1] >= 8) or sys.version_info[0] > 3)'; then
2020
echo >&2 'skipping Hy test -- not allowed on Python 3.8+ (yet!)'
21-
cat expected-std-out.txt # cheaters gunna cheat
21+
# cheaters gunna cheat
22+
cat expected-std-out.txt
2223
exit
2324
fi
2425

25-
pip install -q 'hy==0.16.0'
26+
pip install -q 'hy==0.17.0'
27+
2628
hy ./container.hy

0 commit comments

Comments
 (0)