Skip to content

assert.InDeltaMapValues: prepend key name to error message #1254

@XANi

Description

@XANi

currently the message isn't too helpful, it shows the values that are wrong but does not say which key that value belongs to. Currently test code

assert.InDeltaMapValues(t, map[string]int{"a": 3, "b": 1}, map[string]int{"a": 4, "b": 1}, 0.01)

will just produce

    t_test.go:7: 
        	Error Trace:	/tmp/a/t_test.go:7
        	Error:      	Max difference between 3 and 4 allowed is 0.01, but difference was -1
        	Test:       	TestT

with no indication which value is wrong

I did try to write a patch for it and it does work

https://github.com/efigence/testify/tree/key-name-map-value

--- FAIL: TestT (0.00s)
    t_test.go:7: 
        	Error Trace:	/tmp/a/t_test.go:7
        	Error:      	key["a"]: Max difference between 3 and 4 allowed is 0.01, but difference was -1
        	Test:       	TestT

but it is hacky at best, I wanted to avoid duplicating InDelta but I haven't found a good way to do it

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions