|
15 | 15 | # limitations under the License.
|
16 | 16 |
|
17 | 17 | set -o errexit
|
18 |
| -set -o nounset |
19 | 18 | set -o pipefail
|
20 | 19 |
|
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 |
30 | 21 |
|
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 |
57 | 25 | fi
|
58 | 26 |
|
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