Skip to content
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

🌱 replacing DeepEqual with cmp Diff in tests #8310

Closed

Conversation

DiptoChakrabarty
Copy link
Member

wrapper function to compare cmp diff in case panic occurs with log

What this PR does / why we need it:
replaces reflect.DeepEqual with go-cmp diff function and also creates a wrapper function to perform comparisons that handles panics which can be used for non testing code as suggested in issue discussion. Tests for the same written
Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #8186

Signed-off-by: DiptoChakrabarty <[email protected]>

wrapper function to compare cmp diff in case panic occurs with log

Signed-off-by: DiptoChakrabarty <[email protected]>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 19, 2023
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 19, 2023
@@ -147,7 +147,7 @@ func TestSetResourceBinding(t *testing.T) {
tt.resourceSetBinding.SetBinding(tt.resourceBinding)
exist := false
for _, b := range tt.resourceSetBinding.Resources {
if reflect.DeepEqual(b.ResourceRef, tt.resourceBinding.ResourceRef) {
if diff := cmp.Diff(b.ResourceRef, tt.resourceBinding.ResourceRef); diff == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if diff := cmp.Diff(b.ResourceRef, tt.resourceBinding.ResourceRef); diff == "" {
if cmp.Equal(b.ResourceRef, tt.resourceBinding.ResourceRef) {

How about this?

(same in the other 2 clusterresourcesetbingins_types_test.go files)

func Check(actual interface{}, expected interface{}) (result bool, err error) {
defer func() error {
if recover() != nil {
log.Printf("panic occured got %v expected %v", actual, expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about the logs here. If the error needs to be logged it should be handled by the function using this util function.

@DiptoChakrabarty
Copy link
Member Author

/retest

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign sbueringer for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@DiptoChakrabarty
Copy link
Member Author

/retest

"github.com/google/go-cmp/cmp"
)

// Check compares the actual and expected values provided using the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious what's the motivation for this? are we unexpectedly panicking somewhere atm?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enxebre I added this to catch panic cases if any occurs

it was mentioned in the issue discussion

#8186 (comment)

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 2, 2023
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@vincepri
Copy link
Member

what's the status of this PR?

@fabriziopandini
Copy link
Member

I'm +1 for closing this PR
It is not getting updates for some time now, we can eventually revive it if folks have time
@chrischdi @sbueringer opinions?

@sbueringer
Copy link
Member

/close

Feel free to reopen if you want to continue this work

@k8s-ci-robot
Copy link
Contributor

@sbueringer: Closed this PR.

In response to this:

/close

Feel free to reopen if you want to continue this work

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider replacing reflect.DeepEqual
7 participants