2017-07-05 21:15:59 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
2019-07-31 00:07:30 +00:00
|
|
|
# Run unit tests and create report
|
2017-07-05 21:15:59 +00:00
|
|
|
#
|
|
|
|
# TESTFLAGS - add additional test flags. Ex:
|
|
|
|
#
|
2019-07-31 00:07:30 +00:00
|
|
|
# TESTFLAGS='-v -run TestBuild' hack/test/unit
|
2017-07-05 21:15:59 +00:00
|
|
|
#
|
|
|
|
# TESTDIRS - run tests for specified packages. Ex:
|
|
|
|
#
|
2019-07-31 00:07:30 +00:00
|
|
|
# TESTDIRS='./pkg/term' hack/test/unit
|
2017-07-05 21:15:59 +00:00
|
|
|
#
|
2021-04-27 22:40:39 +00:00
|
|
|
set -eux -o pipefail
|
2017-07-05 21:15:59 +00:00
|
|
|
|
2023-08-25 14:39:33 +00:00
|
|
|
BUILDFLAGS=(-tags 'netgo journald')
|
2019-09-13 14:01:54 +00:00
|
|
|
TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}"
|
2019-07-31 00:07:30 +00:00
|
|
|
TESTDIRS="${TESTDIRS:-./...}"
|
|
|
|
exclude_paths='/vendor/|/integration'
|
2017-07-05 21:15:59 +00:00
|
|
|
pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
|
|
|
|
|
2021-07-02 19:29:04 +00:00
|
|
|
base_pkg_list=$(echo "${pkg_list}" | grep --fixed-strings -v "/libnetwork" || :)
|
|
|
|
libnetwork_pkg_list=$(echo "${pkg_list}" | grep --fixed-strings "/libnetwork" || :)
|
|
|
|
|
|
|
|
echo "${libnetwork_pkg_list}" | grep --fixed-strings "libnetwork/drivers/bridge" \
|
2021-05-28 00:15:56 +00:00
|
|
|
&& if ! type docker-proxy; then
|
2021-04-28 20:08:11 +00:00
|
|
|
hack/make.sh binary-proxy install-proxy
|
|
|
|
fi
|
|
|
|
|
2019-07-31 00:07:30 +00:00
|
|
|
mkdir -p bundles
|
2021-07-02 19:29:04 +00:00
|
|
|
|
|
|
|
if [ -n "${base_pkg_list}" ]; then
|
|
|
|
gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report.json --junitfile=bundles/junit-report.xml -- \
|
|
|
|
"${BUILDFLAGS[@]}" \
|
|
|
|
-cover \
|
2022-08-26 18:19:00 +00:00
|
|
|
-coverprofile=bundles/coverage.out \
|
2021-07-02 19:29:04 +00:00
|
|
|
-covermode=atomic \
|
|
|
|
${TESTFLAGS} \
|
|
|
|
${base_pkg_list}
|
|
|
|
fi
|
|
|
|
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 -- \
|
|
|
|
"${BUILDFLAGS[@]}" \
|
|
|
|
-cover \
|
2022-08-26 18:19:00 +00:00
|
|
|
-coverprofile=bundles/coverage-libnetwork.out \
|
2021-07-02 19:29:04 +00:00
|
|
|
-covermode=atomic \
|
|
|
|
-p=1 \
|
|
|
|
${TESTFLAGS} \
|
|
|
|
${libnetwork_pkg_list}
|
|
|
|
fi
|