#!/bin/bash
set -e
function execute_test() {
if ! (go test -mod=mod -v -race -coverprofile cov.out "${TOP_DIR}"/pkg/... >./"$file_input"); then
cat ./$file_input
echo '****** go test cases error! ******'
exit 1
else
gocov convert cov.out | gocov-html >"$file_detail_output"
gotestsum --junitfile unit-tests.xml "${TOP_DIR}"/pkg/...
total_coverage=$(go tool cover -func=cov.out | grep "total:" | awk '{print $3}'| sed 's/%//')
coverage=$(echo "$total_coverage" | awk '{if ($1 >= 0) print ($1 == int($1)) ? int($1) : int($1) + 1;\
else print ($1 == int($1)) ? int($1) : int($1)}')
if [[ $coverage -ge 80 ]]; then
echo "coverage passed: $coverage%"
exit 0
else
echo "coverage failed: $coverage%, it needs to be greater than 80%."
exit 1
fi
fi
}
function main() {
echo "************************************* Start LLT Test *************************************"
execute_test
echo "************************************* End LLT Test *************************************"
}
export GO111MODULE="on"
export PATH=$GOPATH/bin:$PATH
export GOFLAGS="-gcflags=all=-l"
unset GOPATH
CUR_DIR=$(dirname "$(readlink -f "$0")")
TOP_DIR=$(realpath "${CUR_DIR}"/..)
file_input='testInferOperator.txt'
file_detail_output='api.html'
if [ -f "${TOP_DIR}"/test ]; then
rm -rf "${TOP_DIR}"/test
fi
mkdir -p "${TOP_DIR}"/test
cd "${TOP_DIR}"/test
echo "clean old version test results"
if [ -f "$file_input" ]; then
rm -rf "$file_input"
fi
if [ -f "$file_detail_output" ]; then
rm -rf "$file_detail_output"
fi
main