-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Structurally compare js objects rather than YAML #404
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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.
Why do you want to
safeDump
and thensafeLoad
?Can we simply compare the
ResourceList
returned byconfigs.toResourceList()
? Are there any downsides?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 know that it's a roundabout way to implement it. But in practice, returning
configs.toResourceList()
causes many test failures for us. Mainly these two types of inequalities:and
The first kind of inequality is easy to understand.
safeDump
elides allundefined
properties.The second kind of inequality results from the call to
deepCopy
on line 102kpt-functions-sdk/ts/kpt-functions/src/testing.ts
Line 102 in cfd7628
I haven't dug into the implementation of
Configs.deepCopy
. But basically, before the equality comparison happens, theinput
object goes through adeepCopy
and theexpectedOutput
object doesn't. ThatdeepCopy
is apparently not "equality-safe", however whatever differences it creates disappear again uponsafeDump
.We have already relied on the semantics of post-yaml comparison in our test cases. 44/118 of our test cases break if we directly return
configs.toResourceList()
fromvalueOf
.safeDump
returns a string. And if stringss
andt
are equal (and valid YAML), thensafeLoad(s)
andsafeLoad(t)
must also be equal (safeDump
is deterministic, surely). The proposed change can't break existing tests.Alternatives
Patch the differences
I suppose it's possible to address the two types of equality differences that we have observed above. We can do a
deepCopy
of theo
object that goes into the comparison. We can explicitly filter outundefined
properties with some recursive function. Or maybe modify our kpt functions to be meticulous about this, so that all theundefined
s match up.But how can we know that these two equality differences are the only ones that could appear? Someone else might depend on other aspects of
safeDump
in their tests. It seems a bit arbitrary to patch over these two things specifically.Rich YAML comparison
Maybe the
expect(...).toEqual(...)
can be replaced with some YAML-specific equality comparison function, which takes two YAMLs and outputs a rich diff on the strings? For example a line-based diff. Then we can go back to only usingsafeDump
and notsafeLoad
. That should probably also output readable diffs.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 detailed explanation.