Revert "insert empty objects into config from empty blocks"

This reverts commit 3677522a28.
Later changes negate the need for this, and removing these again
prevents us from having to strip them back out when helper/schema
doesn't want them.
This commit is contained in:
James Bardin 2019-01-12 09:17:58 -05:00
parent 9b89f6ecc6
commit c7269bec02
2 changed files with 16 additions and 12 deletions

View File

@ -80,6 +80,11 @@ func ConfigValueFromHCL2Block(v cty.Value, schema *configschema.Block) map[strin
case configschema.NestingList, configschema.NestingSet:
l := bv.LengthInt()
if l == 0 {
// skip empty collections to better mimic how HCL1 would behave
continue
}
elems := make([]interface{}, 0, l)
for it := bv.ElementIterator(); it.Next(); {
_, ev := it.Element()
@ -92,6 +97,11 @@ func ConfigValueFromHCL2Block(v cty.Value, schema *configschema.Block) map[strin
ret[name] = elems
case configschema.NestingMap:
if bv.LengthInt() == 0 {
// skip empty collections to better mimic how HCL1 would behave
continue
}
elems := make(map[string]interface{})
for it := bv.ElementIterator(); it.Next(); {
ek, ev := it.Element()

View File

@ -151,7 +151,7 @@ func TestConfigValueFromHCL2Block(t *testing.T) {
},
{
cty.ObjectVal(map[string]cty.Value{
"address": cty.ListValEmpty(cty.EmptyObject),
"address": cty.ListValEmpty(cty.EmptyObject), // should be omitted altogether in result
}),
&configschema.Block{
BlockTypes: map[string]*configschema.NestedBlock{
@ -161,9 +161,7 @@ func TestConfigValueFromHCL2Block(t *testing.T) {
},
},
},
map[string]interface{}{
"address": []interface{}{},
},
map[string]interface{}{},
},
{
cty.ObjectVal(map[string]cty.Value{
@ -195,9 +193,7 @@ func TestConfigValueFromHCL2Block(t *testing.T) {
},
},
},
map[string]interface{}{
"address": []interface{}{},
},
map[string]interface{}{},
},
{
cty.ObjectVal(map[string]cty.Value{
@ -229,9 +225,7 @@ func TestConfigValueFromHCL2Block(t *testing.T) {
},
},
},
map[string]interface{}{
"address": map[string]interface{}{},
},
map[string]interface{}{},
},
{
cty.NullVal(cty.EmptyObject),
@ -240,8 +234,8 @@ func TestConfigValueFromHCL2Block(t *testing.T) {
},
}
for i, test := range tests {
t.Run(fmt.Sprintf("%d-%#v", i, test.Input), func(t *testing.T) {
for _, test := range tests {
t.Run(fmt.Sprintf("%#v", test.Input), func(t *testing.T) {
got := ConfigValueFromHCL2Block(test.Input, test.Schema)
if !reflect.DeepEqual(got, test.Want) {
t.Errorf("wrong result\ninput: %#v\ngot: %#v\nwant: %#v", test.Input, got, test.Want)