I want to get the test coverage and compare with user defined threshold. I tried below code in makefile I am referring this link. It is written in .yml file but I am trying to write it in a Makefile.
.PHONY: lint
testcoverage=$(go tool cover -func coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+')
echo ${testcoverage}
if (${testcoverage} -lt 50 ); then \
echo "Please add more unit tests or adjust threshold to a lower value."; \
echo "Failed"
exit 1
else \
echo "OK"; \
fi
It does not print anything on echo ${totaltestcoverage}
and gives answer OK even if my totaltestcoverage is 40.
Can anyone please help me with a better way to get the test coverage and compare with user defined threshold?
Thanks in advance.