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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fix Matchers bug on ignored paths and add tests #5565

Merged

Conversation

killianmuldoon
Copy link
Contributor

Signed-off-by: killianmuldoon kmuldoon@vmware.com

This PR changes the logic inside the matchers to ensure that any difference in fields between the actual and original object - in either direction - is considered significant for establishing whether the objects are Equal. Previously the matcher did no consider fields in the original object that are not present in the modified object when matching.

This PR also adds unit tests to show the intended usage of the matcher in these, and other cases.

Note: This change significantly modifies the behaviour of the matcher library compared to the mergepatch library used in topology/internal. These changes make #5316 more difficult and less desirable.

Fixes #5563

/area testing

@k8s-ci-robot k8s-ci-robot added area/testing Issues or PRs related to testing cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 2, 2021
@killianmuldoon
Copy link
Contributor Author

@sbueringer Can you let me know if this fixes the issues you encountered?

Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

Thx for the very quick fix!!

Worked on my PR. A few nits, otherwise lgtm

internal/matchers/matchers.go Outdated Show resolved Hide resolved
internal/matchers/matchers.go Outdated Show resolved Hide resolved
internal/matchers/matchers.go Show resolved Hide resolved
internal/matchers/matchers_test.go Outdated Show resolved Hide resolved
Comment on lines -129 to -133
originalWithModifiedJSON, err := jsonpatch.MergePatch(originalJSON, actualJSON)
if err != nil {
return nil, err
}
rawDiff, err := jsonpatch.CreateMergePatch(originalJSON, originalWithModifiedJSON)
Copy link
Member

Choose a reason for hiding this comment

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

Sorry I did not noticed this before, this is two-ways merge, but we need a plain merge patch like proposed in this change. Good catch

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 3, 2021
@sbueringer
Copy link
Member

@killianmuldoon Thank you very much! lgtm +/- squash

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

LGTM pending squash

Signed-off-by: killianmuldoon <kmuldoon@vmware.com>
Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 4, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 4, 2021
@k8s-ci-robot k8s-ci-robot merged commit 572819d into kubernetes-sigs:main Nov 4, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.1 milestone Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/testing Issues or PRs related to testing cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EqualObject Matcher ignores additional fields
5 participants