Skip to content

assert: reject incompatible map keys in InDeltaMapValues - #1976

Open
Shubham-Padkonde wants to merge 1 commit into
stretchr:masterfrom
Shubham-Padkonde:fix/in-delta-map-key-types
Open

Shubham-Padkonde wants to merge 1 commit into
stretchr:masterfrom
Shubham-Padkonde:fix/in-delta-map-key-types

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown

Summary

Report a failed InDeltaMapValues assertion 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant