Skip to content

Commit

Permalink
Fix hasComputedValue to handle nested slices
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Aug 1, 2019
1 parent d938fe3 commit f9ed212
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/provider/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ func hasComputedValue(obj *unstructured.Unstructured) bool {
if field, isMap := v.(map[string]interface{}); isMap {
objects = append(objects, field)
}
if field, isSlice := v.([]interface{}); isSlice {
for _, v := range field {
if _, isComputed := v.(resource.Computed); isComputed {
return true
}
if field, isMap := v.(map[string]interface{}); isMap {
objects = append(objects, field)
}
}
}
if field, isSlice := v.([]map[string]interface{}); isSlice {
objects = append(objects, field...)
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/provider/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ func TestHasComputedValue(t *testing.T) {
}},
hasComputedValue: true,
},
{
name: "Object with nested slice of map[string]interface{} has a computed value",
obj: &unstructured.Unstructured{Object: map[string]interface{}{
"field1": 1,
"field2": []map[string]interface{}{
{"field3": resource.Computed{}},
},
}},
hasComputedValue: true,
},
{
name: "Object with nested slice of interface{} has a computed value",
obj: &unstructured.Unstructured{Object: map[string]interface{}{
"field1": 1,
"field2": []interface{}{
resource.Computed{},
},
}},
hasComputedValue: true,
},
}

for _, test := range tests {
Expand Down

0 comments on commit f9ed212

Please sign in to comment.