unit 935 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env bash
  2. #
  3. # Run unit tests
  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 -eu -o pipefail
  14. TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}"
  15. BUILDFLAGS=( -tags "netgo seccomp libdm_no_deferred_remove" )
  16. TESTDIRS="${TESTDIRS:-"./..."}"
  17. exclude_paths="/vendor/|/integration"
  18. pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
  19. # install test dependencies once before running tests for each package. This
  20. # significantly reduces the runtime.
  21. go test -i "${BUILDFLAGS[@]}" $pkg_list
  22. for pkg in $pkg_list; do
  23. go test "${BUILDFLAGS[@]}" \
  24. -cover \
  25. -coverprofile=profile.out \
  26. -covermode=atomic \
  27. $TESTFLAGS \
  28. "${pkg}"
  29. if test -f profile.out; then
  30. cat profile.out >> coverage.txt
  31. rm profile.out
  32. fi
  33. done