github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/hack/test/unit (about) 1 #!/usr/bin/env bash 2 # 3 # Run unit tests and create report 4 # 5 # TESTFLAGS - add additional test flags. Ex: 6 # 7 # TESTFLAGS='-v -run TestBuild' hack/test/unit 8 # 9 # TESTDIRS - run tests for specified packages. Ex: 10 # 11 # TESTDIRS='./pkg/term' hack/test/unit 12 # 13 set -eux -o pipefail 14 15 BUILDFLAGS=(-tags 'netgo journald') 16 TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}" 17 TESTDIRS="${TESTDIRS:-./...}" 18 exclude_paths='/vendor/|/integration' 19 pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)") 20 21 base_pkg_list=$(echo "${pkg_list}" | grep --fixed-strings -v "/libnetwork" || :) 22 libnetwork_pkg_list=$(echo "${pkg_list}" | grep --fixed-strings "/libnetwork" || :) 23 24 echo "${libnetwork_pkg_list}" | grep --fixed-strings "libnetwork/drivers/bridge" \ 25 && if ! type docker-proxy; then 26 hack/make.sh binary-proxy install-proxy 27 fi 28 29 mkdir -p bundles 30 31 if [ -n "${base_pkg_list}" ]; then 32 gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report.json --junitfile=bundles/junit-report.xml -- \ 33 "${BUILDFLAGS[@]}" \ 34 -cover \ 35 -coverprofile=bundles/coverage.out \ 36 -covermode=atomic \ 37 ${TESTFLAGS} \ 38 ${base_pkg_list} 39 fi 40 if [ -n "${libnetwork_pkg_list}" ]; then 41 # libnetwork tests invoke iptables, and cannot be run in parallel. Execute 42 # tests within /libnetwork with '-p=1' to run them sequentially. See 43 # https://github.com/moby/moby/issues/42458#issuecomment-873216754 for details. 44 gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report-libnetwork.json --junitfile=bundles/junit-report-libnetwork.xml -- \ 45 "${BUILDFLAGS[@]}" \ 46 -cover \ 47 -coverprofile=bundles/coverage-libnetwork.out \ 48 -covermode=atomic \ 49 -p=1 \ 50 ${TESTFLAGS} \ 51 ${libnetwork_pkg_list} 52 fi