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
5 changes: 5 additions & 0 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,11 @@ func writePropertiesToBody(missingProperties []propertyPath, bodyParams map[stri
for _, containerName := range prop.path {
innerBodyContainer, bodyOk := currentBodyContainer[containerName]
innerStateContainer, stateOk := currentStateContainer[containerName]
// If the container doesn't exist in either body or state, create it and continue iterating.
// But if it doesn't exist in either, there is no point in continuing.
if !bodyOk && !stateOk {
break
}
if !bodyOk {
innerBodyContainer = map[string]interface{}{}
currentBodyContainer[containerName] = innerBodyContainer
Expand Down
26 changes: 22 additions & 4 deletions provider/pkg/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,27 @@ func TestWritePropertiesToBody(t *testing.T) {
assert.Equal(t, expected, bodyParams)
})

// Regression test for #3036 - do not add empty containers to the body that will not be filled
t.Run("two containers missing from remote", func(t *testing.T) {
missingProperties := []propertyPath{{
propertyName: "remote",
path: []string{"properties", "privateNetworks"},
}}
bodyParams := map[string]interface{}{
"properties": map[string]interface{}{
"existing": "value",
},
}
response := map[string]interface{}{}
writePropertiesToBody(missingProperties, bodyParams, response)
expected := map[string]interface{}{
"properties": map[string]interface{}{
"existing": "value",
},
}
assert.Equal(t, expected, bodyParams)
})

t.Run("properties container missing in body", func(t *testing.T) {
missingProperties := []propertyPath{{
propertyName: "remote",
Expand Down Expand Up @@ -162,10 +183,7 @@ func TestWritePropertiesToBody(t *testing.T) {
bodyParams := map[string]interface{}{}
response := map[string]interface{}{}
writePropertiesToBody(missingProperties, bodyParams, response)
expected := map[string]interface{}{
// Container is auto-created
"properties": map[string]interface{}{},
}
expected := map[string]interface{}{}
assert.Equal(t, expected, bodyParams)
})

Expand Down