[NOD-617] Remove test coverage from test.sh (#569)

* [NOD-617] Remove test coverage from test.sh

* [NOD-617] Log coverage
This commit is contained in:
Ori Newman 2020-01-06 10:31:09 +02:00 committed by stasatdaglabs
parent df91643976
commit 733d06af5a

28
test.sh
View File

@ -1,33 +1,15 @@
#!/bin/sh
set -e
export COVERAGE_PATH="./coverage.txt"
export COVERAGE_TEMP_PATH="./coverage.tmp"
# Remove the old coverage file if exists
rm -f ${COVERAGE_PATH}
# Create a new coverage file
echo 'mode: atomic' > ${COVERAGE_PATH}
# Test each package (excluding vendor packages) separately
# Test each package separately
# Function inlining messes with monkey patching so we disable it by passing -gcflags='-l'
# Running tests with -covermode=atomic saves us from race conditions unique to the testing environment
# We write coverage for every package to a temporary file so that we may append it to one global coverage file
go list ./... | \
grep -v "vendor" | \
xargs -n1 -I{} sh -c "go test -gcflags='-l' -timeout 60s -covermode=atomic -coverprofile=${COVERAGE_TEMP_PATH} {} && tail -n +2 ${COVERAGE_TEMP_PATH} >> ${COVERAGE_PATH}" | \
tee /tmp/test
xargs -n1 -I{} sh -c "go test -gcflags='-l' -timeout 60s -covermode=atomic -cover {}"
# Remove the temporary coverage file
rm -f ${COVERAGE_TEMP_PATH}
# Succeed only if everything is 100% covered
grep "ok .* 100.0% of statements" -v /tmp/test > /tmp/test2 || true
if [ -s /tmp/test2 ]
retVal=$?
if [ $retVal -ne 0 ]
then
echo " >> tests failed or not 100% coverage"
echo " >> tests failed"
exit 1
else
echo " >> tests completed successfully"