jstemmer / go-junit-report

Convert Go test output to JUnit XML
MIT License
764 stars 222 forks source link

Publishing Test Results in Azure Pipelines gives invalid character error #99

Open Divya1388 opened 4 years ago

Divya1388 commented 4 years ago

Configured a pipeline to test and publish results. The test is scripted to test a terraform Plan output. when running the tasks: go get -u github.com/jstemmer/go-junit-report go test -v -timeout 60m 2>&1 | go-junit-report > report.xml and Publish test results The pipline passes but the publish test result task give the following error

[warning]Failed to read D:\a\1\go\src\s***\CentralUS\Global\VirtualNetwork\test\report.xml. Error : '.', hexadecimal value 0x00, is an invalid character. Line 2, position 1..

No build level attachments to publish. Finishing: Publish Test Results D:\a\1\go\src\s**\report.xml

Divya1388 commented 4 years ago

The Publish test results throws error on Windows agent with Error : '.', hexadecimal value 0x00, is an invalid character. Line 2, position 1.. It does not give error on Linux agent

divyanshidm commented 4 years ago

Hi, I am facing the same issue. Did you find a solution to this?

jsoconno commented 2 years ago

I was able to resolve this with something like the following:

<code here to generate the report in the wrong encoding>
Get-Content report.xml -Encoding Unicode | Set-Content -Encoding UTF8 report_utf8.xml

I had to do a similar thing when using Terratest and the terratest_log_parser on Windows:

go test -v -timeout 60m | tee -Variable content
$content | Set-Content -Encoding utf8 test_output.log
terratest_log_parser -testlog test_output.log -outputdir test_output

I don't have the same problem when running these commands on Linux:

go test -v -timeout 30m | tee test_output.log
terratest_log_parser -testlog test_output.log -outputdir test_output

Of course, you would then use the PublishTestResults@2 Azure DevOps task to publish targeting the properly encoded output file.