Update hack/test/unit for go module

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan
2025-07-16 22:36:31 -07:00
parent 1d571e619d
commit 900a0516de

View File

@@ -15,53 +15,55 @@ set -eux -o pipefail
BUILDFLAGS=(-tags 'netgo journald')
TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}"
TESTDIRS="${TESTDIRS:-./...}"
exclude_paths='/vendor/|/integration'
pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
base_pkg_list=$(echo "${pkg_list}" | grep --fixed-strings -v "/libnetwork" | grep --fixed-strings -v "/docker/docker/api" | grep --fixed-strings -v "/docker/docker/client" || :)
api_pkg_list=$(echo "${pkg_list}" | grep --fixed-strings "docker/docker/api" | sed 's/docker\/docker/moby\/moby/' || :)
client_pkg_list=$(echo "${pkg_list}" | grep --fixed-strings "docker/docker/client" | sed 's/docker\/docker/moby\/moby/' || :)
libnetwork_pkg_list=$(echo "${pkg_list}" | grep --fixed-strings "/libnetwork" || :)
mkdir -p bundles
cd api
api_pkg_list=$(go list $TESTDIRS)
if [ -n "${api_pkg_list}" ]; then
gotestsum --format=standard-quiet --jsonfile=../bundles/api-go-test-report.json --junitfile=../bundles/api-junit-report.xml -- \
"${BUILDFLAGS[@]}" \
-cover \
-coverprofile=../bundles/api-coverage.out \
-covermode=atomic \
${TESTFLAGS} \
${api_pkg_list}
fi
cd ../client
client_pkg_list=$(go list $TESTDIRS)
if [ -n "${client_pkg_list}" ]; then
gotestsum --format=standard-quiet --jsonfile=../bundles/client-go-test-report.json --junitfile=../bundles/client-junit-report.xml -- \
"${BUILDFLAGS[@]}" \
-cover \
-coverprofile=../bundles/client-coverage.out \
-covermode=atomic \
${TESTFLAGS} \
${client_pkg_list}
fi
cd ..
exclude_paths='/vendor/|/integration'
pkgs=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
pkg_list=$(echo "${pkgs}" | grep --fixed-strings -v "/libnetwork" || :)
libnetwork_pkg_list=$(echo "${pkgs}" | grep --fixed-strings "/libnetwork" || :)
echo "${libnetwork_pkg_list}" | grep --fixed-strings "libnetwork/drivers/bridge" \
&& if ! type docker-proxy; then
hack/make.sh binary-proxy install-proxy
fi
mkdir -p bundles
if [ -n "${base_pkg_list}" ]; then
if [ -n "${pkg_list}" ]; then
gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report.json --junitfile=bundles/junit-report.xml -- \
"${BUILDFLAGS[@]}" \
-cover \
-coverprofile=bundles/coverage.out \
-covermode=atomic \
${TESTFLAGS} \
${base_pkg_list}
fi
if [ -n "${api_pkg_list}" ]; then
cd api
gotestsum --format=standard-quiet --jsonfile=../bundles/go-test-report-api.json --junitfile=../bundles/junit-report-api.xml -- \
"${BUILDFLAGS[@]}" \
-cover \
-coverprofile=../bundles/coverage-api.out \
-covermode=atomic \
${TESTFLAGS} \
${api_pkg_list}
cd ..
fi
if [ -n "${client_pkg_list}" ]; then
cd client
gotestsum --format=standard-quiet --jsonfile=../bundles/go-test-report-client.json --junitfile=../bundles/junit-report-client.xml -- \
"${BUILDFLAGS[@]}" \
-cover \
-coverprofile=../bundles/coverage-client.out \
-covermode=atomic \
${TESTFLAGS} \
${client_pkg_list}
cd ..
${pkg_list}
fi
if [ -n "${libnetwork_pkg_list}" ]; then
@@ -77,10 +79,10 @@ if [ -n "${libnetwork_pkg_list}" ]; then
# libnetwork tests invoke iptables, and cannot be run in parallel. Execute
# tests within /libnetwork with '-p=1' to run them sequentially. See
# https://github.com/moby/moby/issues/42458#issuecomment-873216754 for details.
gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report-libnetwork.json --junitfile=bundles/junit-report-libnetwork.xml \
gotestsum --format=standard-quiet --jsonfile=bundles/libnetwork-go-test-report.json --junitfile=bundles/libnetwork-junit-report.xml \
-- "${BUILDFLAGS[@]}" \
-cover \
-coverprofile=bundles/coverage-libnetwork.out \
-coverprofile=bundles/libnetwork-coverage.out \
-covermode=atomic \
-p=1 \
${gotest_extra_flags} \
@@ -88,12 +90,12 @@ if [ -n "${libnetwork_pkg_list}" ]; then
${libnetwork_pkg_list}
if [ $rerun_flaky -eq 1 ]; then
gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report-libnetwork-flaky.json --junitfile=bundles/junit-report-libnetwork-flaky.xml \
gotestsum --format=standard-quiet --jsonfile=bundles/libnetwork-flaky-go-test-report.json --junitfile=bundles/libnetwork-flaky-junit-report.xml \
--packages "${libnetwork_pkg_list}" \
--rerun-fails=4 \
-- "${BUILDFLAGS[@]}" \
-cover \
-coverprofile=bundles/coverage-libnetwork-flaky.out \
-coverprofile=bundles/libnetwork-flaky-coverage.out \
-covermode=atomic \
-p=1 \
-test.run 'TestFlaky.*' \