-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testing/slogtest: support sub-tests #61758
Comments
Using sub-tests would also help with another problem: I cannot configure zap to skip the zero time. That's just how it is and https://pkg.go.dev/log/slog#Handler allows it ("should observe", not "must observe"). But in order to pass TestHandler, a handler "must" skip it, which is stronger than required. If it was a sub-test with a known name, then I could skip that one test case. |
Same with "a Handler should not output groups for an empty Record": I'm mapping BTW, "for an empty Record" seems a bit misleading. Perhaps replace with "if they are empty"? |
For example, consider this error that occurs when the handler doesn't use the right field name for "time":
The first error looks okay, but the second doesn't. Another simple fix would be to swap the strings:
|
CC @jba |
See also #61706, which would benefit from skipping the ignore-zero-time test case. |
Edited: added a *testing.T arg to the callbacks. OK, here's a concrete proposal. Let me know what you think. Add a Run function to testing/slogtestWe would like to add the following function:
Unlike the RationaleRunning all test cases on a handler in bulk has a couple of problems:
|
Change https://go.dev/cl/516076 mentions this issue: |
Change https://go.dev/cl/516155 mentions this issue: |
|
Can we pass I'm also wondering about future extensions. We discussed skipping specific test cases. With Should that be considered by the API already now or is it okay to add |
That seems reasonable. I especially like that
I hope we don't have to get that fancy. Anyway, the name will be unique, so someone who wants to skip a subset of cases can always categorize that subset by name. That might be a bit fragile but again, the code only changes once per release. |
Updates #61758. Change-Id: I4ce0359f676b6832e40203e1034ba1c4f6d2b2ed Reviewed-on: https://go-review.googlesource.com/c/go/+/516155 Run-TryBot: Jonathan Amsterdam <[email protected]> Reviewed-by: Patrick Ohly <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
This proposal has been added to the active column of the proposals project |
@pohly I updated my proposal to add Could you edit your top post to link to the proposal, so we know exactly what this issue is proposing? |
Done. In the proposal you might add:
|
@pohly Done. |
Have all remaining concerns about #61758 (comment) been addressed? |
Yes, looks good to me. |
Based on the discussion above, this proposal seems like a likely accept. |
Updates golang#61758. Change-Id: I4ce0359f676b6832e40203e1034ba1c4f6d2b2ed Reviewed-on: https://go-review.googlesource.com/c/go/+/516155 Run-TryBot: Jonathan Amsterdam <[email protected]> Reviewed-by: Patrick Ohly <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
Updates golang#61758. Change-Id: I4ce0359f676b6832e40203e1034ba1c4f6d2b2ed Reviewed-on: https://go-review.googlesource.com/c/go/+/516155 Run-TryBot: Jonathan Amsterdam <[email protected]> Reviewed-by: Patrick Ohly <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
No change in consensus, so accepted. 🎉 |
Proposal
See #61758 (comment)
Original problem statement
I'm in the early stages of adding slog support to zapr. I know that I am not handling all corner cases yet and started using testing/slogtest to see whether that finds the known (and perhaps some unknown) gaps.
Here's what my test currently looks like:
Here's how it fails:
I think the failure is accurate. But initially I had problems understanding the error string:
a Handler should ignore an empty Attr
is a test case instead of additional explanation and thatslogtest.go:74
is where I can find out what exactly that test case covers. Example output in https://pkg.go.dev/testing/slogtest with explanations would help.That could be done without changing the API. But what I'd really love to have instead is an API which allows me to iterate over each test case and run each one as a sub-test. That would enable me to do
dlv test . -- -test.run=TestSlogHandler/ignore.an.empty.Attr
and deal with just that one failure. It'll be immediately obvious what the log output for that test case is because there will only be one line. Parsing that line will also be simpler.cc @jba
The text was updated successfully, but these errors were encountered: