ci: fix shellcheck in test-go

Fixed shellcheck in test-go script

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
Signed-off-by: Niels de Vos <ndevos@redhat.com>
(cherry picked from commit fdbd487741)
This commit is contained in:
Madhu Rajanna 2020-10-27 10:36:05 +05:30 committed by mergify[bot]
parent 6e3d68ee7b
commit 9db673afc7

View File

@ -4,7 +4,7 @@ GOPACKAGES="$(go list -mod=vendor ./... | grep -v -e vendor -e e2e)"
COVERFILE="${GO_COVER_DIR}/profile.cov" COVERFILE="${GO_COVER_DIR}/profile.cov"
# no special options, exec to go test w/ all pkgs # no special options, exec to go test w/ all pkgs
if [[ ${TEST_EXITFIRST} != "yes" && -z ${TEST_COVERAGE} ]]; then if [[ "${TEST_EXITFIRST}" != "yes" && -z "${TEST_COVERAGE}" ]]; then
# shellcheck disable=SC2086 # shellcheck disable=SC2086
exec go test "${GO_TAGS}" -mod=vendor -v ${GOPACKAGES} exec go test "${GO_TAGS}" -mod=vendor -v ${GOPACKAGES}
fi fi
@ -12,7 +12,7 @@ fi
# our options are set so we need to handle each go package one # our options are set so we need to handle each go package one
# at at time # at at time
if [[ ${TEST_COVERAGE} ]]; then if [[ ${TEST_COVERAGE} ]]; then
GOTESTOPTS="-covermode=count -coverprofile=cover.out" GOTESTOPTS=("-covermode=count" "-coverprofile=cover.out")
echo "mode: count" >"${COVERFILE}" echo "mode: count" >"${COVERFILE}"
fi fi
@ -20,23 +20,23 @@ failed=0
for gopackage in ${GOPACKAGES}; do for gopackage in ${GOPACKAGES}; do
echo "--- testing: ${gopackage} ---" echo "--- testing: ${gopackage} ---"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
go test "${GO_TAGS}" -mod=vendor -v ${GOTESTOPTS} "${gopackage}" || ((failed += 1)) go test "${GO_TAGS}" -mod=vendor -v ${GOTESTOPTS[*]} "${gopackage}" || ((failed += 1))
if [[ -f cover.out ]]; then if [[ -f cover.out ]]; then
# Append to coverfile # Append to coverfile
grep -v "^mode: count" cover.out >>"${COVERFILE}" grep -v "^mode: count" cover.out >>"${COVERFILE}"
fi fi
if [[ ${TEST_COVERAGE} = "stdout" && -f cover.out ]]; then if [[ "${TEST_COVERAGE}" = "stdout" && -f cover.out ]]; then
go tool cover -func=cover.out go tool cover -func=cover.out
fi fi
if [[ ${TEST_COVERAGE} = "html" && -f cover.out ]]; then if [[ "${TEST_COVERAGE}" = "html" && -f cover.out ]]; then
mkdir -p coverage mkdir -p coverage
fn="${GO_COVER_DIR}/${gopackage////-}.html" fn="${GO_COVER_DIR}/${gopackage////-}.html"
echo " * generating coverage html: ${fn}" echo " * generating coverage html: ${fn}"
go tool cover -html=cover.out -o "${fn}" go tool cover -html=cover.out -o "${fn}"
fi fi
rm -f cover.out rm -f cover.out
if [[ ${failed} -ne 0 && ${TEST_EXITFIRST} = "yes" ]]; then if [[ "${failed}" -ne 0 && "${TEST_EXITFIRST}" = "yes" ]]; then
exit ${failed} exit "${failed}"
fi fi
done done
exit ${failed} exit "${failed}"