-
Notifications
You must be signed in to change notification settings - Fork 28
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
Make Error and Fatal functions compatible with testing.T #286
base: master
Are you sure you want to change the base?
Conversation
…/f1 into sirockin-tb-compatibility
I'm surprised the CI pipeline is failing on interface compatibility given the changes are non-breaking. |
@sirockin This is a breaking change for any users that may have already done what we're trying here - create an abstraction to share code between f1 and other parts of their codebase. We want to avoid breaking users as much as possible hence my comment on the other PR: #279 (comment) I'm open to ideas, but I still think adding a |
// Special case, single error argument | ||
if len(args) == 1 { | ||
err, ok := args[0].(error) | ||
if ok { | ||
t.logger.Error("iteration failed", log.IterationAttr(t.Iteration), log.ErrorAttr(err)) | ||
t.FailNow() | ||
return | ||
} | ||
} | ||
t.Log(args...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would have different logging depending on the number of arguments.
I think if we just add a new log Attr helper that merges a list of errors, we can handle any number of arguments in a consistent way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick review and useful feedback, @nvloff-f3 .
I'm still not exactly clear on what you are looking for though. The original comment said // Error is equivalent to Log followed by Fail.
(consistent with behaviour of testing.T) so I was aiming to get as close to that as possible.
Please could you clarify the behaviour you would like to see like to see with:
- a single argument of type
error
- a single argument of type other than
error
- more than one argument, all of type
error
- more than one argument, not all of type
error
It would be great if we could create some tests for these scenarios but given the way that concrete logger instances are embedded into t
, that may be difficult to achieve.
It could also be argued that rather than introducing a helper to log the arguments, we should amend Log
so that it does what we want then use that in the methods. This would simplify code, make behaviour consistent across these methods and make the original comments for Error
and Fatal
accurate. However it would mean that we couldn't force logger.Error
to be called if standard printf
arguments were supplied to Error
or Fatal
.
Anyway let me know your thoughts and I'll prepare a commit.
Thanks again!
I may be being dense (it's early in the morning for me 😂 ) but I'm still not clear on why this would be a breaking change. The two methods will still behave exactly as previously for the only case which was previously compilable: a single error argument. |
What
Making
testing.Error
andtesting.Fatal
functions compatible with testing.T by changing the singleerror
argument to a variable argument list acceptingany
.Why
Facilitates reusing test scenarios by extracting common testing interface
Testing
The only tests which currently exist for the two functions confirm that the methods fail the load test do not test the logging functionality. We update these with test cases to cover different arguments being passed in.
Example code
main.go:
main_test.go:
Resolves #278