Structured Plan Renderer: Add tests validating behaviour of dynamic types (#32482)

* add support for dynamic types into attribute processing

* fix names

* add tests
This commit is contained in:
Liam Cervante
2023-01-09 20:08:08 +01:00
committed by GitHub
parent d31631675b
commit 7a3fc48b70
2 changed files with 33 additions and 0 deletions

View File

@@ -49,6 +49,12 @@ func (v Value) computeChangeForType(ctype cty.Type) change.Change {
switch {
case ctype == cty.NilType, ctype == cty.DynamicPseudoType:
// Forward nil or dynamic types over to be processed as outputs.
// There is nothing particularly special about the way outputs are
// processed that make this unsafe, we could just as easily call this
// function computeChangeForDynamicValues(), but external callers will
// only be in this situation when processing outputs so this function
// is named for their benefit.
return v.ComputeChangeForOutput()
case ctype.IsPrimitiveType():
return v.computeAttributeChangeAsPrimitive(ctype)

View File

@@ -1573,6 +1573,33 @@ func TestValue_PrimitiveAttributes(t *testing.T) {
attribute: cty.String,
validateChange: change.ValidatePrimitive(strptr("\"old\""), strptr("\"old\""), plans.NoOp, false),
},
"dynamic": {
input: Value{
Before: "old",
After: "new",
},
attribute: cty.DynamicPseudoType,
validateChange: change.ValidatePrimitive(strptr("\"old\""), strptr("\"new\""), plans.Update, false),
validateSliceChanges: []change.ValidateChangeFunc{
change.ValidatePrimitive(strptr("\"old\""), nil, plans.Delete, false),
change.ValidatePrimitive(nil, strptr("\"new\""), plans.Create, false),
},
},
"dynamic_type_change": {
input: Value{
Before: "old",
After: 4.0,
},
attribute: cty.DynamicPseudoType,
validateChange: change.ValidateTypeChange(
change.ValidatePrimitive(strptr("\"old\""), nil, plans.Delete, false),
change.ValidatePrimitive(nil, strptr("4"), plans.Create, false),
plans.Update, false),
validateSliceChanges: []change.ValidateChangeFunc{
change.ValidatePrimitive(strptr("\"old\""), nil, plans.Delete, false),
change.ValidatePrimitive(nil, strptr("4"), plans.Create, false),
},
},
}
for name, tmp := range tcs {
tc := tmp