Skip to content
Closed
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
27 changes: 27 additions & 0 deletions libs/dyn/convert/end_to_end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func TestAdditional(t *testing.T) {
MapToPointer map[string]*string `json:"map_to_pointer"`
SliceOfPointer []*string `json:"slice_of_pointer"`
NestedStruct StructType `json:"nested_struct"`
MapOfString map[string]string `json:"map_of_string"`
MapOfBool map[string]bool `json:"map_of_bool"`
}

t.Run("nil", func(t *testing.T) {
Expand Down Expand Up @@ -58,4 +60,29 @@ func TestAdditional(t *testing.T) {
SliceOfPointer: []*string{nil},
})
})

t.Run("map with one value", func(t *testing.T) {
assertFromTypedToTypedEqual(t, Tmp{
MapOfString: map[string]string{
"key": "value",
},
})
})

t.Run("map with empty val", func(t *testing.T) {
assertFromTypedToTypedEqual(t, Tmp{
MapOfString: map[string]string{
"key": "",
},
})
})

// Without the changes in this PR, this test case would fail
t.Run("map with empty val", func(t *testing.T) {
assertFromTypedToTypedEqual(t, Tmp{
MapOfBool: map[string]bool{
"key": false,
},
})
})
}
5 changes: 0 additions & 5 deletions libs/dyn/convert/from_typed.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ func fromTypedString(src reflect.Value, ref dyn.Value) (dyn.Value, error) {

return dyn.V(value), nil
case dyn.KindNil:
// This field is not set in the reference, so we only include it if it has a non-zero value.
// Otherwise, we would always include all zero valued fields.
if src.IsZero() {
return dyn.NilValue, nil
}
return dyn.V(src.String()), nil
}

Expand Down