Test2json, more particularly go test -json, has been quite a pleasant discovery. It allows for programs to analyze go tests and create their own formatted output.
For example, using GitHub Actions' formatting capabilities, I was able to better format go tests to look more user friendly when running in the UI:
Before:
After:
With that said, there are still some missing features that would allow programs to better understand the JSON output of a test.
Proposal
It would be great if Go Tests can attach metadata to be included in the JSON output of a test2json run.
This allows for a few highly beneficial use cases:
If a test fails, then the program that's analyzing the failed test's json can receive metadata about why it failed: such as requestID, userID etc and then provide the user helpful links to logs and queries.
A test can provide source-code information about where things failed. Because right now test2json cannot distinguish between when a user called t.Fatal(...) or t.Log(...) which makes sense as t.Fatal just calls t.Log -- but the user can include metadata so we know exactly where the error occurred and use CI capabilities such as Actions' error command to set the file and line number to be displayed in the UI.
Alternative solutions:
Include directives in the output string that the json-parsing program can analyze to see if there's metadata. But this solution is very fragile and prone to error.
Thanks!
The text was updated successfully, but these errors were encountered:
I looked into this a bit; Unfortunately I don't think it can work quite the way you've proposed (at least, not with the current testing architecture). In particular, testing likes to emit everything in a text stream, and the JSON blobs are reconstituted with cmd/test2json from that text stream; it would be really tricky to attach metadata to a particular logging statement.
As an additional wrinkle, encoding/json has a dependency on testing, meaning that testing cannot actually use Go's json package for any encoding :(.
It SHOULD be possible, however, to have something which worked like:
Where ":" is a forbidden character in the key, and the value is trimmed for whitespace.
I think that this functionality might be "good enough" when parsing the test output JSON; metadata would effectively accumulate for the duration of the test, since the test JSON is effectively scanned top-to-bottom anyway to extract information about a given test.
I can write up a CL that we can poke at, if folks don't hate this :)
Test2json, more particularly
go test -json
, has been quite a pleasant discovery. It allows for programs to analyze go tests and create their own formatted output.For example, using GitHub Actions' formatting capabilities, I was able to better format go tests to look more user friendly when running in the UI:
Before:
After:
With that said, there are still some missing features that would allow programs to better understand the JSON output of a test.
Proposal
It would be great if Go Tests can attach metadata to be included in the JSON output of a test2json run.
Something along these lines:
Benefits:
This allows for a few highly beneficial use cases:
test2json
cannot distinguish between when a user calledt.Fatal(...)
ort.Log(...)
which makes sense ast.Fatal
just callst.Log
-- but the user can include metadata so we know exactly where the error occurred and use CI capabilities such as Actions' error command to set the file and line number to be displayed in the UI.Alternative solutions:
Include directives in the output string that the json-parsing program can analyze to see if there's metadata. But this solution is very fragile and prone to error.
Thanks!
The text was updated successfully, but these errors were encountered: