Skip to content

Commit 2c4c33e

Browse files
Added coverage output to make test
1 parent ba0ba3e commit 2c4c33e

File tree

2 files changed

+9
-51
lines changed

2 files changed

+9
-51
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ bin/
1414

1515
# Dependency directories (remove the comment below to include it)
1616
# vendor/
17+
18+
# Test artifacts folder
19+
test-artifacts/

hack/test.sh

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,14 @@
1515
# limitations under the License.
1616

1717
set -o errexit
18-
set -o nounset
1918
set -o pipefail
2019

21-
junitFilenamePrefix() {
22-
if [[ -z "${JUNIT_REPORT_DIR}" ]]; then
23-
echo ""
24-
return
25-
fi
26-
mkdir -p "${JUNIT_REPORT_DIR}"
27-
DATE=$( date +%s | base64 | head -c 15 )
28-
echo "${JUNIT_REPORT_DIR}/junit_$DATE"
29-
}
20+
go test -v -race ./cmd/... ./pkg/... -coverprofile cover.out
3021

31-
function produce_junit_xmlreport {
32-
local -r junit_filename_prefix=$1
33-
if [[ -z "${junit_filename_prefix}" ]]; then
34-
return
35-
fi
36-
37-
local junit_xml_filename
38-
junit_xml_filename="${junit_filename_prefix}.xml"
39-
40-
if ! command -v gotestsum >/dev/null 2>&1; then
41-
echo "gotestsum not found; installing now"
42-
go install gotest.tools/[email protected]
43-
fi
44-
export PATH=$GOBIN:$GOPATH/bin:$PATH
45-
gotestsum --junitfile "${junit_xml_filename}" --raw-command cat "${junit_filename_prefix}"*.stdout
46-
echo "Saved JUnit XML test report to ${junit_xml_filename}"
47-
}
48-
49-
goTestFlags=""
50-
51-
##### Create a junit-style XML test report in this directory if set. #####
52-
JUNIT_REPORT_DIR=${JUNIT_REPORT_DIR:-}
53-
54-
# If JUNIT_REPORT_DIR is unset, and ARTIFACTS is set, then have them match.
55-
if [[ -z "${JUNIT_REPORT_DIR:-}" && -n "${ARTIFACTS:-}" ]]; then
56-
export JUNIT_REPORT_DIR="${ARTIFACTS}"
22+
if [[ -z "${ARTIFACTS}" ]]; then
23+
mkdir -p test-artifacts
24+
export ARTIFACTS=./test-artifacts
5725
fi
5826

59-
# Used to filter verbose test output.
60-
go_test_grep_pattern=".*"
61-
62-
if [[ -n "${JUNIT_REPORT_DIR}" ]] ; then
63-
goTestFlags+="-v "
64-
goTestFlags+="-json "
65-
# Show only summary lines by matching lines like "status package/test"
66-
go_test_grep_pattern="^[^[:space:]]\+[[:space:]]\+[^[:space:]]\+/[^[[:space:]]\+"
67-
fi
68-
69-
junit_filename_prefix=$(junitFilenamePrefix)
70-
71-
go test ${goTestFlags} -race ./cmd/... ./pkg/... | tee ${junit_filename_prefix:+"${junit_filename_prefix}.stdout"} | grep --binary-files=text "${go_test_grep_pattern}"
72-
73-
produce_junit_xmlreport "${junit_filename_prefix}"
27+
cp cover.out "${ARTIFACTS}/cover.out"
28+
go tool cover -html="${ARTIFACTS}/cover.out" -o "${ARTIFACTS}/cover.html"

0 commit comments

Comments
 (0)