Skip to content

Commit

Permalink
Add map test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Watson committed Mar 19, 2024
1 parent 3defce4 commit a7a1269
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
5 changes: 2 additions & 3 deletions fmutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ func (mask NestedMask) overwrite(srcRft, destRft protoreflect.Message) {
srcMap.Range(func(mk protoreflect.MapKey, mv protoreflect.Value) bool {
if mi, ok := submask[mk.String()]; ok {
if i, ok := mv.Interface().(protoreflect.Message); ok && len(mi) > 0 {
destVal := protoreflect.ValueOf(mv)
destMap.Set(mk, destVal)
mi.overwrite(i, destVal.Message())
destMap.Set(mk, mv)
mi.overwrite(i, mv.Message())
} else {
destMap.Set(mk, mv)
}

Check warning on line 193 in fmutils.go

View check run for this annotation

Codecov / codecov/patch

fmutils.go#L192-L193

Added lines #L192 - L193 were not covered by tests
Expand Down
41 changes: 41 additions & 0 deletions fmutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,47 @@ func TestOverwrite(t *testing.T) {
},
},
},
{
name: "overwrite map with message values",
paths: []string{"attributes.src1.tags", "attributes.src2.tags"},
src: &testproto.Profile{
User: nil,
Attributes: map[string]*testproto.Attribute{
"src1": {
Tags: map[string]string{"key1": "value1", "key2": "value2"},
},
"src2": {
Tags: map[string]string{"key3": "value3"},
},
},
},
dest: &testproto.Profile{
User: &testproto.User{
Name: "name",
},
Attributes: map[string]*testproto.Attribute{
"dest1": {
Tags: map[string]string{"key4": "value5"},
},
},
},
want: &testproto.Profile{
User: &testproto.User{
Name: "name",
},
Attributes: map[string]*testproto.Attribute{
"src1": {
Tags: map[string]string{"key1": "value1", "key2": "value2"},
},
"src2": {
Tags: map[string]string{"key3": "value3"},
},
"dest1": {
Tags: map[string]string{"key4": "value5"},
},
},
},
},
{
name: "overwrite repeated message fields",
paths: []string{"gallery.path"},
Expand Down

0 comments on commit a7a1269

Please sign in to comment.