Add tests locking down ChunkID hex formatting - #380
Merged
Conversation
ChunkID.String() and MarshalJSON() were briefly moved to pointer receivers in #273, which meant a ChunkID value was rendered by fmt's byte-array fallback and marshalled as an array of numbers. #379 moved them back to value receivers but added no test, so the same regression could slip in again unnoticed. Cover both the formatting and the JSON encoding of a ChunkID value, including the non-addressable map-value case that skips a pointer-receiver MarshalJSON, plus compile-time assertions that the value type implements fmt.Stringer and json.Marshaler.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
ChunkID.String()andMarshalJSON()were on pointer receivers between #273 and #379, which meant aChunkIDvalue passed to%s/%v/%qwas rendered byfmt's byte-array fallback, and a non-addressableChunkIDwas marshalled as an array of numbers. #379 moved both back to value receivers but didn't add a test, so the same regression could slip back in unnoticed.This adds
types_test.gocovering:ChunkIDvalue (and pointer) with%s,%vand%q, plusChunkMissing.Error()which formats the ID by valuejson.Marshalof aChunkIDin a map value — map values aren't addressable, so a pointer-receiverMarshalJSONis skipped there and the ID comes out as an array of numbers[]ChunkAdditionalInforound trip used byinspect-chunksChunkID(not just*ChunkID) implementsfmt.Stringerandjson.Marshaler, so a receiver change fails the build rather than silently changing outputVerified the tests catch the regression: reverting both methods to pointer receivers fails
TestChunkIDFormatting(raw bytes instead of hex) andTestChunkIDMarshalJSON(number array instead of a hex string).