Skip to content

Fix broken test output

Go's own internal test2json and the test to junit project we use both rely on converting Go test output to JSON and then processing.

Unfortunetly, when using go test -v, logs sent to stdout/stderr produce malformed test output, which then cannot be parsed correctly and converted to JSON.

An example of the problem can be seen in this log output:

=== RUN   TestArtifactsDownloader/legacy#02/retries_are_called
WARNING: Retrying...                                error=invalid argument
WARNING: Retrying...                                error=invalid argument
invalid argument=== RUN   TestArtifactsDownloader/fastzip#02
=== RUN   TestArtifactsDownloader/fastzip#02/retries_are_called
WARNING: Retrying...                                error=invalid argument
WARNING: Retrying...                                error=invalid argument
invalid argument=== RUN   TestArtifactsDownloader/legacy#03
=== RUN   TestArtifactsDownloader/legacy#03/first_try_is_always_direct_download

===RUN is intended to be at the beginning of the line, but invalid argument appears at the start, breaking the conversion.


Fortunately for us, this only ever occurs when we use tests with MakeFatalToPanic. The panic produced from this as part of the tests doesn't terminate the log line with a new line. The fix is making MakeFatalToPanic add a newline to the output (as is done in non-test environments).