Skip to content

Commit 509bec9

Browse files
committed
Run upstream tests on images in CI here
This runs upstream's `dist test` which is roughly `go test std cmd`.
1 parent 8d54278 commit 509bec9

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

.test/config.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
# https://github.com/docker-library/official-images/blob/3bc6a70175d4e1da2080b86415e6f3c8eb2c6af3/test/config.sh
4+
5+
imageTests[golang]+='
6+
go-dist-test
7+
'

.test/tests/go-dist-test/run.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
image="$1"
5+
6+
args=(
7+
# respond better to SIGINT/SIGTERM
8+
--init --interactive
9+
10+
# Go has some tests that are very picky about DNS resolution
11+
--dns 8.8.8.8
12+
--dns 8.8.4.4
13+
)
14+
15+
cmd=(
16+
# the "dist" tool doesn't query Go for GOROOT and expects it to be set explicitly
17+
sh -xec 'GOROOT="$(go env GOROOT)" && export GOROOT && exec "$@"' --
18+
19+
go tool dist test
20+
)
21+
22+
case "$image" in
23+
*alpine*)
24+
# Alpine needs a few extra dependencies installed for the tests to run/pass
25+
# gcc/libc-dev: cgo-related tests
26+
# iproute2-minimal: BusyBox's "ip" isn't enough for tests that need to shell out to "ip" for various env setup
27+
cmd=( sh -xec 'apk add --no-cache gcc libc-dev iproute2-minimal && exec "$@"' -- "${cmd[@]}" )
28+
# for some reason, running the tests on Alpine needs NET_ADMIN (but not on Debian 🤔)
29+
args+=( --cap-add NET_ADMIN )
30+
;;
31+
32+
*windows* | *nanoserver*)
33+
echo >&2 "note: tests do not run successfully in a Windows container yet (https://github.com/docker-library/golang/issues/552#issuecomment-2658011431)"
34+
exit 0
35+
;;
36+
esac
37+
38+
if [ -t 0 ] && [ -t 1 ]; then
39+
# let Ctrl+C DTRT if we're at a TTY
40+
args+=( --tty )
41+
fi
42+
43+
docker run --rm "${args[@]}" "$image" "${cmd[@]}"

0 commit comments

Comments
 (0)