-
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
Merged
metlos
merged 7 commits into
codeready-toolchain:master
from
metlos:dump-objects-on-wait-for-condition-error
Feb 22, 2024
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bbee2ce
Enable nice reporting of test failures caused by the not matching pre…
metlos 9f5567b
Rewrite the SpaceProvisionerConfig predicates to support diff reporting.
metlos f9ca8d4
fix failing test and add more for the basic predicate fixers.
metlos 67f3c03
Merge branch 'master' into dump-objects-on-wait-for-condition-error
metlos fa8b9f0
Adding a short note about the role of - and + in the diffs
metlos 554737c
fix the test
metlos 2c2e36e
Make most of the AssertThat logic testable and write a simple test fo…
metlos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package assertions | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func TestExplain(t *testing.T) { | ||
t.Run("with diff", func(t *testing.T) { | ||
// given | ||
actual := &corev1.Secret{} | ||
actual.SetName("actual") | ||
|
||
pred := Has(Name("expected")) | ||
|
||
// when | ||
expl := Explain(pred, actual) | ||
|
||
// then | ||
assert.True(t, strings.HasPrefix(expl, "predicate 'assertions.named' didn't match the object because of the following differences:")) | ||
assert.Contains(t, expl, "-") | ||
assert.Contains(t, expl, "\"expected\"") | ||
assert.Contains(t, expl, "+") | ||
assert.Contains(t, expl, "\"actual\"") | ||
}) | ||
|
||
t.Run("without diff", func(t *testing.T) { | ||
// given | ||
actual := &corev1.Secret{} | ||
actual.SetName("actual") | ||
|
||
pred := &predicateWithoutFixing{} | ||
|
||
// when | ||
expl := Explain(pred, actual) | ||
|
||
// then | ||
assert.Equal(t, expl, "predicate 'assertions.predicateWithoutFixing' didn't match the object") | ||
}) | ||
} | ||
|
||
type predicateWithoutFixing struct{} | ||
|
||
var _ Predicate[client.Object] = (*predicateWithoutFixing)(nil) | ||
|
||
func (*predicateWithoutFixing) Matches(obj client.Object) bool { | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.