Ensure deterministic order when diffing maps #1822
Open
+24
−0
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.
Summary
Ensure deterministic order when diffing maps to make the diffs readable.
Changes
Enable the
SpewKeyssetting inspew.ConfigState.Motivation
When generating the diff for two maps where the map key is not a basic type, the order is non-deterministic which makes the diffs unreadable.
By enabling the
SpewKeyssetting, the map keys will be spewed to strings for the purpose of sorting them. This results in a deterministic order and makes the diffs readable.For the test case added in this PR, the old config that has
SpewKeysdisabled would look like this:After enabling
SpewKeys, we get the simpler diff that we would expect: