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