2019-02-07 09:56:39 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-10-04 13:58:13 +00:00
|
|
|
MOD_VENDOR=$(test -d vendor && echo '-mod=vendor')
|
|
|
|
GOPACKAGES="$(go list "${MOD_VENDOR}" ./... | grep -v -e vendor -e e2e)"
|
2020-03-12 07:03:47 +00:00
|
|
|
COVERFILE="${GO_COVER_DIR}/profile.cov"
|
2019-02-07 09:56:39 +00:00
|
|
|
|
|
|
|
# no special options, exec to go test w/ all pkgs
|
2020-10-27 05:06:05 +00:00
|
|
|
if [[ "${TEST_EXITFIRST}" != "yes" && -z "${TEST_COVERAGE}" ]]; then
|
2019-02-07 09:56:39 +00:00
|
|
|
# shellcheck disable=SC2086
|
2021-10-04 13:58:13 +00:00
|
|
|
exec go test ${GO_TAGS} ${MOD_VENDOR} -v ${GOPACKAGES}
|
2019-02-07 09:56:39 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# our options are set so we need to handle each go package one
|
|
|
|
# at at time
|
|
|
|
if [[ ${TEST_COVERAGE} ]]; then
|
2020-10-27 05:06:05 +00:00
|
|
|
GOTESTOPTS=("-covermode=count" "-coverprofile=cover.out")
|
2020-03-12 07:03:47 +00:00
|
|
|
echo "mode: count" >"${COVERFILE}"
|
2019-02-07 09:56:39 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
failed=0
|
|
|
|
for gopackage in ${GOPACKAGES}; do
|
|
|
|
echo "--- testing: ${gopackage} ---"
|
|
|
|
# shellcheck disable=SC2086
|
2022-11-15 17:31:30 +00:00
|
|
|
go test "${GO_TAGS}" "${MOD_VENDOR}" -v "${GOTESTOPTS[@]}" "${gopackage}" || ((failed += 1))
|
2019-02-07 09:56:39 +00:00
|
|
|
if [[ -f cover.out ]]; then
|
|
|
|
# Append to coverfile
|
2020-03-12 07:03:47 +00:00
|
|
|
grep -v "^mode: count" cover.out >>"${COVERFILE}"
|
2019-02-07 09:56:39 +00:00
|
|
|
fi
|
2020-10-27 05:06:05 +00:00
|
|
|
if [[ "${TEST_COVERAGE}" = "stdout" && -f cover.out ]]; then
|
2019-02-07 09:56:39 +00:00
|
|
|
go tool cover -func=cover.out
|
|
|
|
fi
|
2020-10-27 05:06:05 +00:00
|
|
|
if [[ "${TEST_COVERAGE}" = "html" && -f cover.out ]]; then
|
2019-02-07 09:56:39 +00:00
|
|
|
mkdir -p coverage
|
2020-06-22 14:48:41 +00:00
|
|
|
fn="${GO_COVER_DIR}/${gopackage////-}.html"
|
2019-02-07 09:56:39 +00:00
|
|
|
echo " * generating coverage html: ${fn}"
|
|
|
|
go tool cover -html=cover.out -o "${fn}"
|
|
|
|
fi
|
|
|
|
rm -f cover.out
|
2020-10-27 05:06:05 +00:00
|
|
|
if [[ "${failed}" -ne 0 && "${TEST_EXITFIRST}" = "yes" ]]; then
|
|
|
|
exit "${failed}"
|
2019-02-07 09:56:39 +00:00
|
|
|
fi
|
|
|
|
done
|
2020-10-27 05:06:05 +00:00
|
|
|
exit "${failed}"
|