assert: reject incompatible map keys in InDeltaMapValues - #1976
Open
Shubham-Padkonde wants to merge 1 commit into
Open
Shubham-Padkonde wants to merge 1 commit into
Shubham-Padkonde wants to merge 1 commit into
Conversation
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.
Summary
Report a failed
InDeltaMapValuesassertion instead of panicking when an expected map key cannot be assigned to the actual map's key type.Changes
Check key assignability before calling
reflect.Value.MapIndex. Preserve the existing concrete-key to interface-key comparison and include caller-supplied assertion messages in the failure.Regressions cover string/int, int/int64, and interface/string map keys. All three panic on the original implementation. A compatible string/interface case continues to pass.
Motivation
assert.InDeltaMapValues(t, map[string]float64{"1": 1}, map[int]float64{1: 1}, 0.1)currently raises a reflection panic. An assertion receiving incompatible maps should report a useful failure rather than abort the current test with a panic. This fixes failure handling without adding an API or converting keys.Validation
The full Ubuntu suite passes with
go test -race ./...;go vet ./...passes.go generate ./...completes without changing generated files, and gofmt/diff checks pass.The initial Windows full-suite attempt encountered dependency-download restrictions, file-test failures, and suite-runner failures. Validation above is from Ubuntu, matching the project's CI platform; this does not claim a successful Windows full-suite run.