mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
decode change values with marks
Marks stored in a plans.ChangeSrc were not decoded along with the stored values. This was working in many cases by evaluation correctly re-evaluating the marks, but this cannot happen in all cases.
This commit is contained in:
parent
4a93399c60
commit
e29eb78cfd
@ -200,9 +200,10 @@ func (cs *ChangeSrc) Decode(ty cty.Type) (*Change, error) {
|
||||
return nil, fmt.Errorf("error decoding 'after' value: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
return &Change{
|
||||
Action: cs.Action,
|
||||
Before: before,
|
||||
After: after,
|
||||
Before: before.MarkWithPaths(cs.BeforeValMarks),
|
||||
After: after.MarkWithPaths(cs.AfterValMarks),
|
||||
}, nil
|
||||
}
|
||||
|
41
plans/changes_test.go
Normal file
41
plans/changes_test.go
Normal file
@ -0,0 +1,41 @@
|
||||
package plans
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
func TestChangeEncodeSensitive(t *testing.T) {
|
||||
testVals := []cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"ding": cty.StringVal("dong").Mark("sensitive"),
|
||||
}),
|
||||
cty.StringVal("bleep").Mark("bloop"),
|
||||
cty.ListVal([]cty.Value{cty.UnknownVal(cty.String).Mark("sup?")}),
|
||||
}
|
||||
|
||||
for _, v := range testVals {
|
||||
t.Run(fmt.Sprintf("%#v", v), func(t *testing.T) {
|
||||
change := Change{
|
||||
Before: cty.NullVal(v.Type()),
|
||||
After: v,
|
||||
}
|
||||
|
||||
encoded, err := change.Encode(v.Type())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
decoded, err := encoded.Decode(v.Type())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !v.RawEquals(decoded.After) {
|
||||
t.Fatalf("%#v != %#v\n", decoded.After, v)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user