unit 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. BUILDFLAGS=(-tags 'netgo journald')
  15. TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}"
  16. TESTDIRS="${TESTDIRS:-./...}"
  17. exclude_paths='/vendor/|/integration'
  18. pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
  19. base_pkg_list=$(echo "${pkg_list}" | grep --fixed-strings -v "/libnetwork" || :)
  20. libnetwork_pkg_list=$(echo "${pkg_list}" | grep --fixed-strings "/libnetwork" || :)
  21. echo "${libnetwork_pkg_list}" | grep --fixed-strings "libnetwork/drivers/bridge" \
  22. && if ! type docker-proxy; then
  23. hack/make.sh binary-proxy install-proxy
  24. fi
  25. mkdir -p bundles
  26. if [ -n "${base_pkg_list}" ]; then
  27. gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report.json --junitfile=bundles/junit-report.xml -- \
  28. "${BUILDFLAGS[@]}" \
  29. -cover \
  30. -coverprofile=bundles/coverage.out \
  31. -covermode=atomic \
  32. ${TESTFLAGS} \
  33. ${base_pkg_list}
  34. fi
  35. if [ -n "${libnetwork_pkg_list}" ]; then
  36. # libnetwork tests invoke iptables, and cannot be run in parallel. Execute
  37. # tests within /libnetwork with '-p=1' to run them sequentially. See
  38. # https://github.com/moby/moby/issues/42458#issuecomment-873216754 for details.
  39. gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report-libnetwork.json --junitfile=bundles/junit-report-libnetwork.xml -- \
  40. "${BUILDFLAGS[@]}" \
  41. -cover \
  42. -coverprofile=bundles/coverage-libnetwork.out \
  43. -covermode=atomic \
  44. -p=1 \
  45. ${TESTFLAGS} \
  46. ${libnetwork_pkg_list}
  47. fi