Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/nil_storage_close
Browse files Browse the repository at this point in the history
  • Loading branch information
mimir-d authored May 9, 2024
2 parents bc439f1 + 1b1abe5 commit eec3e27
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 12 additions & 0 deletions pkg/test/param_expander.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ func (pe *ParamExpander) ExpandObject(obj interface{}, out interface{}) error {
vout.Set(val)

case reflect.Map:
if vin.IsNil() {
// handle nil maps, eg. map[T]U(nil)
vout.Set(vin)
break
}

val := reflect.MakeMap(vin.Type())
iter := vin.MapRange()
for iter.Next() {
Expand Down Expand Up @@ -112,6 +118,12 @@ func (pe *ParamExpander) ExpandObject(obj interface{}, out interface{}) error {
vout.Set(val.Elem())

case reflect.Slice:
if vin.IsNil() {
// handle nil slices, eg. []T(nil)
vout.Set(vin)
break
}

elemType := vin.Type().Elem()
len := vin.Len()

Expand Down
12 changes: 10 additions & 2 deletions pkg/test/param_expander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,18 @@ func TestParamExpander(t *testing.T) {

t.Run("nulls", func(t *testing.T) {
type testObj struct {
Str *string
Intf any
Str *string
Intf any
Ints []int
IntMap map[int]int
}

// both fields null
input := &testObj{}
require.Nil(t, input.Str)
require.Nil(t, input.Intf)
require.Nil(t, input.Ints)
require.Nil(t, input.IntMap)

e := NewParamExpander(target, &mockVars{})

Expand All @@ -180,5 +186,7 @@ func TestParamExpander(t *testing.T) {

require.Nil(t, out.Str)
require.Nil(t, out.Intf)
require.Nil(t, out.Ints)
require.Nil(t, out.IntMap)
})
}

0 comments on commit eec3e27

Please sign in to comment.