Closed icholy closed 5 years ago
Thank you for contribution. I don't like an idea of adding unnecessary operation to the encoding just to make the tests passing. I think this should be solved on the test level.
@kolo are you opposed because of the performance overhead?
@icholy mostly, but it also doesn't look good from my point of view.
My original plan was to have a unexported flag to only enable this behavior during tests and I decided against that for the following reasons:
fmt.Printf
function to sort map keys for the exact same reason.I don't have a strong preference either way. I'll add the flag if you'd prefer that approach.
I think having a flag is a good compromise.
@kolo since these are only running during tests, I've switched to using sort.Slice
to shorten up the code.
Since map iteration order is randomised, the tests randomly pass/fail. This change sorts the map keys before encoding to keep the output deterministic. Now the test always pass.