-
Notifications
You must be signed in to change notification settings - Fork 22
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
Enable diff reporting on predicates #362
Enable diff reporting on predicates #362
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #362 +/- ##
=======================================
Coverage 76.42% 76.42%
=======================================
Files 43 43
Lines 1998 1998
=======================================
Hits 1527 1527
Misses 424 424
Partials 47 47 |
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.
Very nice!
I have one comment regarding breaking API changes though.
func AssertThat(t *testing.T, object client.Object, predicate Predicate[client.Object], msgAndArgs ...any) { | ||
// Note that this method accepts multiple predicates and reports any failures in them using | ||
// the Explain function. | ||
func AssertThat(t *testing.T, object client.Object, predicates ...Predicate[client.Object]) { |
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.
Since you are changing a signature of an existing function let's be careful with breaking components which uses it. We need to get the other PRs ready or we can consider introducing a new function and keep the current one deprecated while updating all the dependencies.
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.
I have checked the code base in all repositories for this. Since this was introduced only very recently, it was used only on a couple of places, and none of them used the removed vararg parameter. So at this time, this is a "source compatible" change.
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.
Great. Thanks for checking.
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 is really nice!
I'm not totally sure I understand the value of Is
and Has
other than making the code sound more like a sentence but I guess it's not something that'd need to be changed/maintained often so probably doesn't hurt?
Really nice improvements overall. 🙌
Not sure if I missed it but if there's one thing I'd suggest it's including which of -
/+
are actual/expected in the explanations because that always trips me up when it's not stated but maybe that's just me.
So the reason for I wanted the But that, of course, brings problems when you want to mix predicates that work on different types. E.g. if you want to combine, say, the The obvious solution to that problem would be to make the common predicates like Note that in languages with more advanced type system, it is possible to leave out the type params, e.g. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=02027f0a894b6e3389fb7619cbd5d0b4 and I believe we could implement something similar in Java, too, using wildcards. I tried quite hard to come up with something that would be both type-safe and ergonomic to write in Go but I failed. So the "backup plan" is to use the wrappers |
I'm the same! :) I modified the output to include a short note about that. |
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.
Nice work 🥇
Thanks a lot for adding diff capabilities to the new generic functions.
Quality Gate passedIssues Measures |
This adds additional interface that the Predicate implementations can implement to enable reporting of the differences that caused the predicate to not match. This will be used in the toolchain-e2e wait.For()... methods to aid in debugging the e2e test failures from the logs. The changes in toolchain-e2e are here: codeready-toolchain/toolchain-e2e#897
In toolchain-common, the
AssertThat
function has also been updated to take advantage of this new diffing capability. Before, the output of theAssertThat
function could be specified similarly toassert.*
functions using the "message and arguments` array. While this possibility has been removed, the method gained the ability to report the diffs that caused the predicates to fail.Let's consider the following (fabricated) example:
The
AssertThat
will cause a test failure with the following error message: