Skip to content

assert.Equal panic on diff unexported map with array as key #1813

@olitez

Description

@olitez

Description

assert.Equal could panic in some cases:

  1. values must be same type but not equal
  2. type must be struct with unexported field
  3. field must be map with array as keys
  4. map must have at least 2 values

Step To Reproduce

type test struct {
	m map[[1]byte]*struct{}
}

a := test{
	map[[1]byte]*struct{}{
		{1}: nil,
		{2}: nil,
	},
}
b := test{}

assert.Equal(t, a, b)

https://go.dev/play/p/1tziFuRiCw4

Expected behavior

show diff

Actual behavior

--- FAIL: TestTest (0.00s)
panic: reflect.Value.Interface: cannot return value obtained from unexported field or method [recovered]
	panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

It fails on diff when trying to obtain dump from davecgh/go-spew, it's long time no updates nor fixes so probably worth to switch on something like yassinebenaid/godump

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions