Skip to content

Commit 6d20904

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 2a49384 commit 6d20904

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
# ideally this would just be "go tool dist test" but it isn't built by default (because most users don't need it)
20+
go run cmd/dist test
21+
)
22+
23+
case "$image" in
24+
*alpine*)
25+
# Alpine needs a few extra dependencies installed for the tests to run/pass
26+
# gcc/libc-dev: cgo-related tests
27+
# iproute2-minimal: BusyBox's "ip" isn't enough for tests that need to shell out to "ip" for various env setup
28+
cmd=( sh -xec 'apk add --no-cache gcc libc-dev iproute2-minimal && exec "$@"' -- "${cmd[@]}" )
29+
# for some reason, running the tests on Alpine needs NET_ADMIN (but not on Debian 🤔)
30+
args+=( --cap-add NET_ADMIN )
31+
;;
32+
33+
*windows* | *nanoserver*)
34+
echo >&2 "note: tests do not run successfully in a Windows container yet (https://github.com/docker-library/golang/issues/552#issuecomment-2658011431)"
35+
exit 0
36+
;;
37+
esac
38+
39+
if [ -t 0 ] && [ -t 1 ]; then
40+
# let Ctrl+C DTRT if we're at a TTY
41+
args+=( --tty )
42+
fi
43+
44+
docker run --rm "${args[@]}" "$image" "${cmd[@]}"

0 commit comments

Comments
 (0)