-
Notifications
You must be signed in to change notification settings - Fork 3
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
Match protojson's output field order #40
Conversation
return err.Error(), nil | ||
} | ||
return "", nil | ||
return golden.GenGoldenContent(filePath, data) |
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 am super-confused by the previous formulation that you've replaced. It looks like it basically always returned the empty string on success, instead of string(data)
. But the new formulation "round-trips" the file and returns the contents after re-marshaling.
All that intended? Mind adding some remarks in a comment or in the PR description to provide some guidance on some of this diff?
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.
Yes, I added a new 'class' of tests for valid .yaml files, that verifies the marshalled output is as expected.
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.
(basically, it validates that everything is normalized and in the right order for valid .yamls)
see #36
JSON objects are unmarshaled into (unordered) go maps by default. This PR uses yaml.Node (when possible) instead, which preserves the field order from protojson.
Note that yaml refuses to parse control characters into yaml.Nodes, though otherwise handle them correctly.