mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
Structured Plan Renderer: Remove generic interface{}
entry point (#32477)
* Remove the single generic point of entry into the differ package * goimports * add comment explaining generic function
This commit is contained in:
parent
9bc5ded27a
commit
1332d315b6
@ -8,46 +8,60 @@ import (
|
||||
"github.com/hashicorp/terraform/internal/command/jsonprovider"
|
||||
)
|
||||
|
||||
func (v Value) computeChangeForAttribute(attribute *jsonprovider.Attribute) change.Change {
|
||||
func (v Value) ComputeChangeForAttribute(attribute *jsonprovider.Attribute) change.Change {
|
||||
if attribute.AttributeNestedType != nil {
|
||||
return v.computeChangeForNestedAttribute(attribute.AttributeNestedType)
|
||||
}
|
||||
return v.computeChangeForType(unmarshalAttribute(attribute))
|
||||
}
|
||||
|
||||
func (v Value) computeChangeForNestedAttribute(attribute *jsonprovider.NestedType) change.Change {
|
||||
switch attribute.NestingMode {
|
||||
func (v Value) computeChangeForNestedAttribute(nested *jsonprovider.NestedType) change.Change {
|
||||
if sensitive, ok := v.checkForSensitive(); ok {
|
||||
return sensitive
|
||||
}
|
||||
|
||||
if computed, ok := v.checkForComputedNestedAttribute(nested); ok {
|
||||
return computed
|
||||
}
|
||||
|
||||
switch nested.NestingMode {
|
||||
case "single", "group":
|
||||
return v.computeAttributeChangeAsNestedObject(attribute.Attributes)
|
||||
return v.computeAttributeChangeAsNestedObject(nested.Attributes)
|
||||
case "map":
|
||||
return v.computeAttributeChangeAsNestedMap(attribute.Attributes)
|
||||
return v.computeAttributeChangeAsNestedMap(nested.Attributes)
|
||||
case "list":
|
||||
return v.computeAttributeChangeAsNestedList(attribute.Attributes)
|
||||
return v.computeAttributeChangeAsNestedList(nested.Attributes)
|
||||
case "set":
|
||||
return v.computeAttributeChangeAsNestedSet(attribute.Attributes)
|
||||
return v.computeAttributeChangeAsNestedSet(nested.Attributes)
|
||||
default:
|
||||
panic("unrecognized nesting mode: " + attribute.NestingMode)
|
||||
panic("unrecognized nesting mode: " + nested.NestingMode)
|
||||
}
|
||||
}
|
||||
|
||||
func (v Value) computeChangeForType(ctyType cty.Type) change.Change {
|
||||
if ctyType == cty.NilType {
|
||||
return v.ComputeChangeForOutput()
|
||||
func (v Value) computeChangeForType(ctype cty.Type) change.Change {
|
||||
if sensitive, ok := v.checkForSensitive(); ok {
|
||||
return sensitive
|
||||
}
|
||||
|
||||
if computed, ok := v.checkForComputedType(ctype); ok {
|
||||
return computed
|
||||
}
|
||||
|
||||
switch {
|
||||
case ctyType.IsPrimitiveType():
|
||||
return v.computeAttributeChangeAsPrimitive(ctyType)
|
||||
case ctyType.IsObjectType():
|
||||
return v.computeAttributeChangeAsObject(ctyType.AttributeTypes())
|
||||
case ctyType.IsMapType():
|
||||
return v.computeAttributeChangeAsMap(ctyType.ElementType())
|
||||
case ctyType.IsListType():
|
||||
return v.computeAttributeChangeAsList(ctyType.ElementType())
|
||||
case ctyType.IsSetType():
|
||||
return v.computeAttributeChangeAsSet(ctyType.ElementType())
|
||||
case ctype == cty.NilType, ctype == cty.DynamicPseudoType:
|
||||
return v.ComputeChangeForOutput()
|
||||
case ctype.IsPrimitiveType():
|
||||
return v.computeAttributeChangeAsPrimitive(ctype)
|
||||
case ctype.IsObjectType():
|
||||
return v.computeAttributeChangeAsObject(ctype.AttributeTypes())
|
||||
case ctype.IsMapType():
|
||||
return v.computeAttributeChangeAsMap(ctype.ElementType())
|
||||
case ctype.IsListType():
|
||||
return v.computeAttributeChangeAsList(ctype.ElementType())
|
||||
case ctype.IsSetType():
|
||||
return v.computeAttributeChangeAsSet(ctype.ElementType())
|
||||
default:
|
||||
panic("unrecognized type: " + ctyType.FriendlyName())
|
||||
panic("unrecognized type: " + ctype.FriendlyName())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,15 @@ import (
|
||||
"github.com/hashicorp/terraform/internal/plans"
|
||||
)
|
||||
|
||||
func (v Value) computeChangeForBlock(block *jsonprovider.Block) change.Change {
|
||||
func (v Value) ComputeChangeForBlock(block *jsonprovider.Block) change.Change {
|
||||
if sensitive, ok := v.checkForSensitive(); ok {
|
||||
return sensitive
|
||||
}
|
||||
|
||||
if computed, ok := v.checkForComputedBlock(block); ok {
|
||||
return computed
|
||||
}
|
||||
|
||||
current := v.getDefaultActionForIteration()
|
||||
|
||||
blockValue := v.asMap()
|
||||
@ -14,7 +22,7 @@ func (v Value) computeChangeForBlock(block *jsonprovider.Block) change.Change {
|
||||
attributes := make(map[string]change.Change)
|
||||
for key, attr := range block.Attributes {
|
||||
childValue := blockValue.getChild(key)
|
||||
childChange := childValue.ComputeChange(attr)
|
||||
childChange := childValue.ComputeChangeForAttribute(attr)
|
||||
if childChange.GetAction() == plans.NoOp && childValue.Before == nil && childValue.After == nil {
|
||||
// Don't record nil values at all in blocks.
|
||||
continue
|
||||
@ -48,7 +56,7 @@ func (v Value) computeChangesForBlockType(blockType *jsonprovider.BlockType) ([]
|
||||
case "map":
|
||||
return v.computeBlockChangesAsMap(blockType.Block)
|
||||
case "single", "group":
|
||||
ch := v.ComputeChange(blockType.Block)
|
||||
ch := v.ComputeChangeForBlock(blockType.Block)
|
||||
return []change.Change{ch}, ch.GetAction()
|
||||
default:
|
||||
panic("unrecognized nesting mode: " + blockType.NestingMode)
|
||||
|
@ -1,10 +1,30 @@
|
||||
package differ
|
||||
|
||||
import (
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
|
||||
"github.com/hashicorp/terraform/internal/command/jsonformat/change"
|
||||
"github.com/hashicorp/terraform/internal/command/jsonprovider"
|
||||
)
|
||||
|
||||
func (v Value) checkForComputed(changeType interface{}) (change.Change, bool) {
|
||||
func (v Value) checkForComputedType(ctype cty.Type) (change.Change, bool) {
|
||||
return v.checkForComputed(func(value Value) change.Change {
|
||||
return value.computeChangeForType(ctype)
|
||||
})
|
||||
}
|
||||
func (v Value) checkForComputedNestedAttribute(attribute *jsonprovider.NestedType) (change.Change, bool) {
|
||||
return v.checkForComputed(func(value Value) change.Change {
|
||||
return value.computeChangeForNestedAttribute(attribute)
|
||||
})
|
||||
}
|
||||
|
||||
func (v Value) checkForComputedBlock(block *jsonprovider.Block) (change.Change, bool) {
|
||||
return v.checkForComputed(func(value Value) change.Change {
|
||||
return value.ComputeChangeForBlock(block)
|
||||
})
|
||||
}
|
||||
|
||||
func (v Value) checkForComputed(computeChange func(value Value) change.Change) (change.Change, bool) {
|
||||
unknown := v.isUnknown()
|
||||
|
||||
if !unknown {
|
||||
@ -17,7 +37,7 @@ func (v Value) checkForComputed(changeType interface{}) (change.Change, bool) {
|
||||
v.AfterExplicit = true
|
||||
|
||||
if v.Before == nil {
|
||||
return v.AsChange(change.Computed(change.Change{})), true
|
||||
return v.asChange(change.Computed(change.Change{})), true
|
||||
}
|
||||
|
||||
// If we get here, then we have a before value. We're going to model a
|
||||
@ -28,7 +48,7 @@ func (v Value) checkForComputed(changeType interface{}) (change.Change, bool) {
|
||||
Before: v.Before,
|
||||
BeforeSensitive: v.BeforeSensitive,
|
||||
}
|
||||
return v.AsChange(change.Computed(beforeValue.ComputeChange(changeType))), true
|
||||
return v.asChange(change.Computed(computeChange(beforeValue))), true
|
||||
}
|
||||
|
||||
func (v Value) isUnknown() bool {
|
||||
|
@ -14,7 +14,7 @@ func (v Value) computeAttributeChangeAsList(elementType cty.Type) change.Change
|
||||
var elements []change.Change
|
||||
current := v.getDefaultActionForIteration()
|
||||
v.processList(elementType.IsObjectType(), func(value Value) {
|
||||
element := value.ComputeChange(elementType)
|
||||
element := value.computeChangeForType(elementType)
|
||||
elements = append(elements, element)
|
||||
current = compareActions(current, element.GetAction())
|
||||
})
|
||||
@ -25,7 +25,10 @@ func (v Value) computeAttributeChangeAsNestedList(attributes map[string]*jsonpro
|
||||
var elements []change.Change
|
||||
current := v.getDefaultActionForIteration()
|
||||
v.processNestedList(func(value Value) {
|
||||
element := value.ComputeChange(attributes)
|
||||
element := value.computeChangeForNestedAttribute(&jsonprovider.NestedType{
|
||||
Attributes: attributes,
|
||||
NestingMode: "single",
|
||||
})
|
||||
elements = append(elements, element)
|
||||
current = compareActions(current, element.GetAction())
|
||||
})
|
||||
@ -36,7 +39,7 @@ func (v Value) computeBlockChangesAsList(block *jsonprovider.Block) ([]change.Ch
|
||||
var elements []change.Change
|
||||
current := v.getDefaultActionForIteration()
|
||||
v.processNestedList(func(value Value) {
|
||||
element := value.ComputeChange(block)
|
||||
element := value.ComputeChangeForBlock(block)
|
||||
elements = append(elements, element)
|
||||
current = compareActions(current, element.GetAction())
|
||||
})
|
||||
|
@ -12,7 +12,7 @@ func (v Value) computeAttributeChangeAsMap(elementType cty.Type) change.Change {
|
||||
current := v.getDefaultActionForIteration()
|
||||
elements := make(map[string]change.Change)
|
||||
v.processMap(func(key string, value Value) {
|
||||
element := value.ComputeChange(elementType)
|
||||
element := value.computeChangeForType(elementType)
|
||||
elements[key] = element
|
||||
current = compareActions(current, element.GetAction())
|
||||
})
|
||||
@ -23,7 +23,10 @@ func (v Value) computeAttributeChangeAsNestedMap(attributes map[string]*jsonprov
|
||||
current := v.getDefaultActionForIteration()
|
||||
elements := make(map[string]change.Change)
|
||||
v.processMap(func(key string, value Value) {
|
||||
element := value.ComputeChange(attributes)
|
||||
element := value.computeChangeForNestedAttribute(&jsonprovider.NestedType{
|
||||
Attributes: attributes,
|
||||
NestingMode: "single",
|
||||
})
|
||||
elements[key] = element
|
||||
current = compareActions(current, element.GetAction())
|
||||
})
|
||||
@ -34,7 +37,7 @@ func (v Value) computeBlockChangesAsMap(block *jsonprovider.Block) ([]change.Cha
|
||||
current := v.getDefaultActionForIteration()
|
||||
var elements []change.Change
|
||||
v.processMap(func(key string, value Value) {
|
||||
element := value.ComputeChange(block)
|
||||
element := value.ComputeChangeForBlock(block)
|
||||
elements = append(elements, element)
|
||||
current = compareActions(current, element.GetAction())
|
||||
})
|
||||
|
@ -9,36 +9,36 @@ import (
|
||||
)
|
||||
|
||||
func (v Value) computeAttributeChangeAsObject(attributes map[string]cty.Type) change.Change {
|
||||
var keys []string
|
||||
for key := range attributes {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
|
||||
attributeChanges, changeType := v.processObject(keys, func(key string) interface{} {
|
||||
return attributes[key]
|
||||
attributeChanges, changeType := processObject(v, attributes, func(value Value, ctype cty.Type) change.Change {
|
||||
return value.computeChangeForType(ctype)
|
||||
})
|
||||
return change.New(change.Object(attributeChanges), changeType, v.replacePath())
|
||||
}
|
||||
|
||||
func (v Value) computeAttributeChangeAsNestedObject(attributes map[string]*jsonprovider.Attribute) change.Change {
|
||||
var keys []string
|
||||
for key := range attributes {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
|
||||
attributeChanges, changeType := v.processObject(keys, func(key string) interface{} {
|
||||
return attributes[key]
|
||||
attributeChanges, changeType := processObject(v, attributes, func(value Value, attribute *jsonprovider.Attribute) change.Change {
|
||||
return value.ComputeChangeForAttribute(attribute)
|
||||
})
|
||||
return change.New(change.NestedObject(attributeChanges), changeType, v.replacePath())
|
||||
}
|
||||
|
||||
func (v Value) processObject(keys []string, getAttribute func(string) interface{}) (map[string]change.Change, plans.Action) {
|
||||
// processObject steps through the children of value as if it is an object and
|
||||
// calls out to the provided computeChange function once it has collated the
|
||||
// diffs for each child attribute.
|
||||
//
|
||||
// We have to make this generic as attributes and nested objects process either
|
||||
// cty.Type or jsonprovider.Attribute children respectively. And we want to
|
||||
// reuse as much code as possible.
|
||||
//
|
||||
// Also, as it generic we cannot make this function a method on Value as you
|
||||
// can't create generic methods on structs. Instead, we make this a generic
|
||||
// function that receives the value as an argument.
|
||||
func processObject[T any](v Value, attributes map[string]T, computeChange func(Value, T) change.Change) (map[string]change.Change, plans.Action) {
|
||||
attributeChanges := make(map[string]change.Change)
|
||||
mapValue := v.asMap()
|
||||
|
||||
currentAction := v.getDefaultActionForIteration()
|
||||
for _, key := range keys {
|
||||
attribute := getAttribute(key)
|
||||
for key, attribute := range attributes {
|
||||
attributeValue := mapValue.getChild(key)
|
||||
|
||||
// We always assume changes to object are implicit.
|
||||
@ -47,7 +47,7 @@ func (v Value) processObject(keys []string, getAttribute func(string) interface{
|
||||
|
||||
// We use the generic ComputeChange here, as we don't know whether this
|
||||
// is from a nested object or a `normal` object.
|
||||
attributeChange := attributeValue.ComputeChange(attribute)
|
||||
attributeChange := computeChange(attributeValue, attribute)
|
||||
if attributeChange.GetAction() == plans.NoOp && attributeValue.Before == nil && attributeValue.After == nil {
|
||||
// We skip attributes of objects that are null both before and
|
||||
// after. We don't even count these as unchanged attributes.
|
||||
|
@ -3,9 +3,10 @@ package differ
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
|
||||
"github.com/hashicorp/terraform/internal/command/jsonformat/change"
|
||||
"github.com/hashicorp/terraform/internal/plans"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -18,6 +19,14 @@ const (
|
||||
)
|
||||
|
||||
func (v Value) ComputeChangeForOutput() change.Change {
|
||||
if sensitive, ok := v.checkForSensitive(); ok {
|
||||
return sensitive
|
||||
}
|
||||
|
||||
if computed, ok := v.checkForComputedType(cty.DynamicPseudoType); ok {
|
||||
return computed
|
||||
}
|
||||
|
||||
beforeType := getJsonType(v.Before)
|
||||
afterType := getJsonType(v.After)
|
||||
|
||||
@ -34,9 +43,9 @@ func (v Value) ComputeChangeForOutput() change.Change {
|
||||
case jsonNumber:
|
||||
res = v.computeAttributeChangeAsPrimitive(cty.Number)
|
||||
case jsonObject:
|
||||
res = v.computeAttributeChangeAsMap(cty.NilType)
|
||||
res = v.computeAttributeChangeAsMap(cty.DynamicPseudoType)
|
||||
case jsonArray:
|
||||
res = v.computeAttributeChangeAsList(cty.NilType)
|
||||
res = v.computeAttributeChangeAsList(cty.DynamicPseudoType)
|
||||
default:
|
||||
panic("unrecognized json type: " + jsonType)
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ func strptr(str string) *string {
|
||||
return &str
|
||||
}
|
||||
|
||||
func (v Value) computeAttributeChangeAsPrimitive(ctyType cty.Type) change.Change {
|
||||
return v.AsChange(change.Primitive(formatAsPrimitive(v.Before, ctyType), formatAsPrimitive(v.After, ctyType)))
|
||||
func (v Value) computeAttributeChangeAsPrimitive(ctype cty.Type) change.Change {
|
||||
return v.asChange(change.Primitive(formatAsPrimitive(v.Before, ctype), formatAsPrimitive(v.After, ctype)))
|
||||
}
|
||||
|
||||
func formatAsPrimitive(value interface{}, ctyType cty.Type) *string {
|
||||
|
@ -10,7 +10,7 @@ func (v Value) checkForSensitive() (change.Change, bool) {
|
||||
return change.Change{}, false
|
||||
}
|
||||
|
||||
return v.AsChange(change.Sensitive(v.Before, v.After, beforeSensitive, afterSensitive)), true
|
||||
return v.asChange(change.Sensitive(v.Before, v.After, beforeSensitive, afterSensitive)), true
|
||||
}
|
||||
|
||||
func (v Value) isBeforeSensitive() bool {
|
||||
|
@ -14,7 +14,7 @@ func (v Value) computeAttributeChangeAsSet(elementType cty.Type) change.Change {
|
||||
var elements []change.Change
|
||||
current := v.getDefaultActionForIteration()
|
||||
v.processSet(false, func(value Value) {
|
||||
element := value.ComputeChange(elementType)
|
||||
element := value.computeChangeForType(elementType)
|
||||
elements = append(elements, element)
|
||||
current = compareActions(current, element.GetAction())
|
||||
})
|
||||
@ -25,7 +25,10 @@ func (v Value) computeAttributeChangeAsNestedSet(attributes map[string]*jsonprov
|
||||
var elements []change.Change
|
||||
current := v.getDefaultActionForIteration()
|
||||
v.processSet(true, func(value Value) {
|
||||
element := value.ComputeChange(attributes)
|
||||
element := value.computeChangeForNestedAttribute(&jsonprovider.NestedType{
|
||||
Attributes: attributes,
|
||||
NestingMode: "single",
|
||||
})
|
||||
elements = append(elements, element)
|
||||
current = compareActions(current, element.GetAction())
|
||||
})
|
||||
@ -36,7 +39,7 @@ func (v Value) computeBlockChangesAsSet(block *jsonprovider.Block) ([]change.Cha
|
||||
var elements []change.Change
|
||||
current := v.getDefaultActionForIteration()
|
||||
v.processSet(true, func(value Value) {
|
||||
element := value.ComputeChange(block)
|
||||
element := value.ComputeChangeForBlock(block)
|
||||
elements = append(elements, element)
|
||||
current = compareActions(current, element.GetAction())
|
||||
})
|
||||
|
@ -2,14 +2,10 @@ package differ
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
|
||||
"github.com/hashicorp/terraform/internal/command/jsonformat/change"
|
||||
"github.com/hashicorp/terraform/internal/command/jsonplan"
|
||||
"github.com/hashicorp/terraform/internal/command/jsonprovider"
|
||||
"github.com/hashicorp/terraform/internal/plans"
|
||||
)
|
||||
|
||||
@ -18,7 +14,7 @@ import (
|
||||
// jsonprovider).
|
||||
//
|
||||
// A Value can be converted into a change.Change, ready for rendering, with the
|
||||
// computeChangeForAttribute, ComputeChangeForOutput, and computeChangeForBlock
|
||||
// ComputeChangeForAttribute, ComputeChangeForOutput, and ComputeChangeForBlock
|
||||
// functions.
|
||||
//
|
||||
// The Before and After fields are actually go-cty values, but we cannot convert
|
||||
@ -98,37 +94,7 @@ func ValueFromJsonChange(change jsonplan.Change) Value {
|
||||
}
|
||||
}
|
||||
|
||||
// ComputeChange is a generic function that lets callers not worry about what
|
||||
// type of change they are processing. In general, this is the function external
|
||||
// users should call as it has some generic preprocessing applicable to all
|
||||
// types.
|
||||
//
|
||||
// It can accept blocks, attributes, go-cty types, and outputs, and will route
|
||||
// the request to the appropriate function.
|
||||
func (v Value) ComputeChange(changeType interface{}) change.Change {
|
||||
if sensitive, ok := v.checkForSensitive(); ok {
|
||||
return sensitive
|
||||
}
|
||||
|
||||
if computed, ok := v.checkForComputed(changeType); ok {
|
||||
return computed
|
||||
}
|
||||
|
||||
switch concrete := changeType.(type) {
|
||||
case *jsonprovider.Attribute:
|
||||
return v.computeChangeForAttribute(concrete)
|
||||
case cty.Type:
|
||||
return v.computeChangeForType(concrete)
|
||||
case map[string]*jsonprovider.Attribute:
|
||||
return v.computeAttributeChangeAsNestedObject(concrete)
|
||||
case *jsonprovider.Block:
|
||||
return v.computeChangeForBlock(concrete)
|
||||
default:
|
||||
panic(fmt.Sprintf("unrecognized change type: %T", changeType))
|
||||
}
|
||||
}
|
||||
|
||||
func (v Value) AsChange(renderer change.Renderer) change.Change {
|
||||
func (v Value) asChange(renderer change.Renderer) change.Change {
|
||||
return change.New(renderer, v.calculateChange(), v.replacePath())
|
||||
}
|
||||
|
||||
|
@ -594,17 +594,17 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
}
|
||||
|
||||
if tc.validateObject != nil {
|
||||
tc.validateObject(t, tc.input.ComputeChange(attribute))
|
||||
tc.validateObject(t, tc.input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
if tc.validateSingleChange != nil {
|
||||
tc.validateSingleChange(t, tc.input.ComputeChange(attribute))
|
||||
tc.validateSingleChange(t, tc.input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
validate := change.ValidateObject(tc.validateChanges, tc.validateAction, tc.validateReplace)
|
||||
validate(t, tc.input.ComputeChange(attribute))
|
||||
validate(t, tc.input.ComputeChangeForAttribute(attribute))
|
||||
})
|
||||
|
||||
t.Run("map", func(t *testing.T) {
|
||||
@ -618,7 +618,7 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
validate := change.ValidateMap(map[string]change.ValidateChangeFunc{
|
||||
"element": tc.validateObject,
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
@ -626,14 +626,14 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
validate := change.ValidateMap(map[string]change.ValidateChangeFunc{
|
||||
"element": tc.validateSingleChange,
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
validate := change.ValidateMap(map[string]change.ValidateChangeFunc{
|
||||
"element": change.ValidateObject(tc.validateChanges, tc.validateAction, tc.validateReplace),
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
})
|
||||
|
||||
t.Run("list", func(t *testing.T) {
|
||||
@ -647,7 +647,7 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
validate := change.ValidateList([]change.ValidateChangeFunc{
|
||||
tc.validateObject,
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
@ -655,14 +655,14 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
validate := change.ValidateList([]change.ValidateChangeFunc{
|
||||
tc.validateSingleChange,
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
validate := change.ValidateList([]change.ValidateChangeFunc{
|
||||
change.ValidateObject(tc.validateChanges, tc.validateAction, tc.validateReplace),
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
})
|
||||
|
||||
t.Run("set", func(t *testing.T) {
|
||||
@ -679,7 +679,7 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
ret = append(ret, tc.validateSetChanges.After.Validate(change.ValidateObject))
|
||||
return ret
|
||||
}(), collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
@ -687,7 +687,7 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
validate := change.ValidateSet([]change.ValidateChangeFunc{
|
||||
tc.validateObject,
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
@ -695,14 +695,14 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
validate := change.ValidateSet([]change.ValidateChangeFunc{
|
||||
tc.validateSingleChange,
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
validate := change.ValidateSet([]change.ValidateChangeFunc{
|
||||
change.ValidateObject(tc.validateChanges, tc.validateAction, tc.validateReplace),
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
})
|
||||
})
|
||||
|
||||
@ -724,17 +724,17 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
}
|
||||
|
||||
if tc.validateNestedObject != nil {
|
||||
tc.validateNestedObject(t, tc.input.ComputeChange(attribute))
|
||||
tc.validateNestedObject(t, tc.input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
if tc.validateSingleChange != nil {
|
||||
tc.validateSingleChange(t, tc.input.ComputeChange(attribute))
|
||||
tc.validateSingleChange(t, tc.input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
validate := change.ValidateNestedObject(tc.validateChanges, tc.validateAction, tc.validateReplace)
|
||||
validate(t, tc.input.ComputeChange(attribute))
|
||||
validate(t, tc.input.ComputeChangeForAttribute(attribute))
|
||||
})
|
||||
|
||||
t.Run("map", func(t *testing.T) {
|
||||
@ -759,7 +759,7 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
validate := change.ValidateMap(map[string]change.ValidateChangeFunc{
|
||||
"element": tc.validateNestedObject,
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
@ -767,14 +767,14 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
validate := change.ValidateMap(map[string]change.ValidateChangeFunc{
|
||||
"element": tc.validateSingleChange,
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
validate := change.ValidateMap(map[string]change.ValidateChangeFunc{
|
||||
"element": change.ValidateNestedObject(tc.validateChanges, tc.validateAction, tc.validateReplace),
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
})
|
||||
|
||||
t.Run("list", func(t *testing.T) {
|
||||
@ -799,7 +799,7 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
validate := change.ValidateNestedList([]change.ValidateChangeFunc{
|
||||
tc.validateNestedObject,
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
@ -807,14 +807,14 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
validate := change.ValidateNestedList([]change.ValidateChangeFunc{
|
||||
tc.validateSingleChange,
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
validate := change.ValidateNestedList([]change.ValidateChangeFunc{
|
||||
change.ValidateNestedObject(tc.validateChanges, tc.validateAction, tc.validateReplace),
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
})
|
||||
|
||||
t.Run("set", func(t *testing.T) {
|
||||
@ -842,7 +842,7 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
ret = append(ret, tc.validateSetChanges.After.Validate(change.ValidateNestedObject))
|
||||
return ret
|
||||
}(), collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
@ -850,7 +850,7 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
validate := change.ValidateSet([]change.ValidateChangeFunc{
|
||||
tc.validateNestedObject,
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
@ -858,14 +858,14 @@ func TestValue_ObjectAttributes(t *testing.T) {
|
||||
validate := change.ValidateSet([]change.ValidateChangeFunc{
|
||||
tc.validateSingleChange,
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
validate := change.ValidateSet([]change.ValidateChangeFunc{
|
||||
change.ValidateNestedObject(tc.validateChanges, tc.validateAction, tc.validateReplace),
|
||||
}, collectionDefaultAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -1109,7 +1109,7 @@ func TestValue_BlockAttributesAndNestedBlocks(t *testing.T) {
|
||||
tc.validate,
|
||||
},
|
||||
}, plans.Update, false)
|
||||
validate(t, input.ComputeChange(block))
|
||||
validate(t, input.ComputeChangeForBlock(block))
|
||||
})
|
||||
t.Run("map", func(t *testing.T) {
|
||||
input := Value{
|
||||
@ -1139,7 +1139,7 @@ func TestValue_BlockAttributesAndNestedBlocks(t *testing.T) {
|
||||
tc.validate,
|
||||
},
|
||||
}, plans.Update, false)
|
||||
validate(t, input.ComputeChange(block))
|
||||
validate(t, input.ComputeChangeForBlock(block))
|
||||
})
|
||||
t.Run("list", func(t *testing.T) {
|
||||
input := Value{
|
||||
@ -1169,7 +1169,7 @@ func TestValue_BlockAttributesAndNestedBlocks(t *testing.T) {
|
||||
tc.validate,
|
||||
},
|
||||
}, plans.Update, false)
|
||||
validate(t, input.ComputeChange(block))
|
||||
validate(t, input.ComputeChangeForBlock(block))
|
||||
})
|
||||
t.Run("set", func(t *testing.T) {
|
||||
input := Value{
|
||||
@ -1202,7 +1202,7 @@ func TestValue_BlockAttributesAndNestedBlocks(t *testing.T) {
|
||||
return []change.ValidateChangeFunc{tc.validate}
|
||||
}(),
|
||||
}, plans.Update, false)
|
||||
validate(t, input.ComputeChange(block))
|
||||
validate(t, input.ComputeChangeForBlock(block))
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -1428,7 +1428,7 @@ func TestValue_Outputs(t *testing.T) {
|
||||
|
||||
for name, tc := range tcs {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
tc.validateChange(t, tc.input.ComputeChange(cty.NilType))
|
||||
tc.validateChange(t, tc.input.ComputeChangeForOutput())
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1584,7 +1584,7 @@ func TestValue_PrimitiveAttributes(t *testing.T) {
|
||||
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Run("direct", func(t *testing.T) {
|
||||
tc.validateChange(t, tc.input.ComputeChange(&jsonprovider.Attribute{
|
||||
tc.validateChange(t, tc.input.ComputeChangeForAttribute(&jsonprovider.Attribute{
|
||||
AttributeType: unmarshalType(t, tc.attribute),
|
||||
}))
|
||||
})
|
||||
@ -1598,7 +1598,7 @@ func TestValue_PrimitiveAttributes(t *testing.T) {
|
||||
validate := change.ValidateMap(map[string]change.ValidateChangeFunc{
|
||||
"element": tc.validateChange,
|
||||
}, defaultCollectionsAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
})
|
||||
|
||||
t.Run("list", func(t *testing.T) {
|
||||
@ -1609,14 +1609,14 @@ func TestValue_PrimitiveAttributes(t *testing.T) {
|
||||
|
||||
if tc.validateSliceChanges != nil {
|
||||
validate := change.ValidateList(tc.validateSliceChanges, defaultCollectionsAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
validate := change.ValidateList([]change.ValidateChangeFunc{
|
||||
tc.validateChange,
|
||||
}, defaultCollectionsAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
})
|
||||
|
||||
t.Run("set", func(t *testing.T) {
|
||||
@ -1627,14 +1627,14 @@ func TestValue_PrimitiveAttributes(t *testing.T) {
|
||||
|
||||
if tc.validateSliceChanges != nil {
|
||||
validate := change.ValidateSet(tc.validateSliceChanges, defaultCollectionsAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
return
|
||||
}
|
||||
|
||||
validate := change.ValidateSet([]change.ValidateChangeFunc{
|
||||
tc.validateChange,
|
||||
}, defaultCollectionsAction, false)
|
||||
validate(t, input.ComputeChange(attribute))
|
||||
validate(t, input.ComputeChangeForAttribute(attribute))
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -1969,7 +1969,7 @@ func TestValue_CollectionAttributes(t *testing.T) {
|
||||
|
||||
for name, tc := range tcs {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
tc.validateChange(t, tc.input.ComputeChange(tc.attribute))
|
||||
tc.validateChange(t, tc.input.ComputeChangeForAttribute(tc.attribute))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user