jstemmer / go-junit-report

Convert Go test output to JUnit XML
MIT License
776 stars 224 forks source link

go-junit-report reports success after failing to compile code #173

Closed tzachshabtay closed 11 months ago

tzachshabtay commented 11 months ago

We upgraded golang for our build docker image to use golang 1.21 but forgot to update our test image that runs go-junit-report so it was still running go 1.20.5. We used the slices package which is only available in 1.21.

Out CI unit test step then reported:

internal/ourpackage/ourfile.go:7:2: package slices is not in GOROOT (/usr/local/go/src/slices)
note: imported by a module that requires go 1.21
Test resulted with exit code of 0

No tests actually ran but the tool returned exit code 0 which means it reported success, and it took us a few weeks to find that out, so we deployed to production versions that were not unit tested!!!

Tested it today with go install github.com/jstemmer/go-junit-report/v2@latest to verify that this is still a bug in the latest version.

Running go test -coverprofile=coverage.out -v -race ./... 2>&1 | go-junit-report -iocopy -set-exit-code -out junit.xml

tzachshabtay commented 11 months ago

Never mind, closing this bug, the issue is we didn't do set -o pipefail which will fail the pipeline if go test fails.

Though it might be worth adding this to the "usage" section in the readme.