mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
handle unset computed values in tests
The old testDiffFn used th raw config to dynamically set computed values in the diff. Since the schema now defines what values should be there, all test diffs end up with unkown computed values. Filter these out by looking for a value set to "compute"
This commit is contained in:
parent
77bc36abce
commit
d55d623ef0
@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/hil"
|
||||
"github.com/hashicorp/terraform/config/configschema"
|
||||
"github.com/hashicorp/terraform/configs"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
@ -234,6 +235,26 @@ func testDiffFn(
|
||||
}
|
||||
|
||||
if k == "compute" {
|
||||
if v == hil.UnknownValue {
|
||||
// compute wasn't set in the config, so don't use these
|
||||
// computed values from the schema.
|
||||
delete(c.Raw, k)
|
||||
delete(c.Raw, "compute_value")
|
||||
|
||||
// we need to remove this from the list of ComputedKeys too,
|
||||
// since it would get re-added to the diff further down
|
||||
newComputed := make([]string, 0, len(c.ComputedKeys))
|
||||
for _, ck := range c.ComputedKeys {
|
||||
if ck == "compute" || ck == "compute_value" {
|
||||
continue
|
||||
}
|
||||
newComputed = append(newComputed, ck)
|
||||
}
|
||||
c.ComputedKeys = newComputed
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
attrDiff := &ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "",
|
||||
@ -248,7 +269,6 @@ func testDiffFn(
|
||||
}
|
||||
|
||||
diff.Attributes[v.(string)] = attrDiff
|
||||
continue
|
||||
}
|
||||
|
||||
// If this key is not computed, then look it up in the
|
||||
@ -579,6 +599,10 @@ func testProviderSchema(name string) *ProviderSchema {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
},
|
||||
"__template_requires_new": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -242,10 +242,6 @@ func NewResourceConfigShimmed(val cty.Value, schema *configschema.Block) *Resour
|
||||
}
|
||||
ret := &ResourceConfig{}
|
||||
|
||||
// Computed fields will all be present with unknown values. Strip them out
|
||||
// before passing to the provider.
|
||||
val = cty.UnknownAsNull(val)
|
||||
|
||||
legacyVal := hcl2shim.ConfigValueFromHCL2(val)
|
||||
ret.Config = legacyVal.(map[string]interface{}) // guaranteed compatible because we require an object type
|
||||
ret.Raw = ret.Config
|
||||
|
Loading…
Reference in New Issue
Block a user