Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions libs/structs/structdiff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,14 @@ func TestGetStructDiffNamedStringMapKey(t *testing.T) {
assert.Equal(t, []ResolvedChange{{Field: "m['pre']", Old: "a", New: "b"}}, resolveChanges(got))
}

func TestIsEqualNamedStringMapKey(t *testing.T) {
a := namedKeyMapHolder{M: map[namedMapKey]string{"pre": "a", "post": "x"}}
b := namedKeyMapHolder{M: map[namedMapKey]string{"pre": "b", "post": "x"}}

assert.True(t, IsEqual(&a, &a))
assert.False(t, IsEqual(&a, &b))
}

// Types for the "whole block" tests below: two levels of nesting under an
// optional pointer, mirroring a schema like Outer{Field *Mid{A *Inner{b,c}}}.
type wbInner struct {
Expand Down
9 changes: 4 additions & 5 deletions libs/structs/structdiff/equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,12 @@ func equalStruct(s1, s2 reflect.Value) bool {
func equalMapStringKey(m1, m2 reflect.Value) bool {
keySet := map[string]reflect.Value{}
for _, k := range m1.MapKeys() {
// Key is always string at this point
ks := k.Interface().(string)
keySet[ks] = k
// Key kind is always String at this point; Value.String() also handles a
// named string key type, where a .(string) assertion panics.
keySet[k.String()] = k
}
for _, k := range m2.MapKeys() {
ks := k.Interface().(string)
keySet[ks] = k
keySet[k.String()] = k
}

for _, k := range keySet {
Expand Down
Loading