test for null map and fix lost map marks

Add a test to ensure ignore_changes does not change null maps to empty
maps.

Fix when a marked map revers the changes ignored within that map.
This commit is contained in:
James Bardin 2021-11-11 10:42:36 -05:00
parent 40174b634a
commit 9d19086c8e
2 changed files with 49 additions and 1 deletions

View File

@ -1301,7 +1301,7 @@ func processIgnoreChangesIndividual(prior, config cty.Value, ignoreChangesPath [
}
if len(vMarks) > 0 {
newVal = v.WithMarks(vMarks)
newVal = newVal.WithMarks(vMarks)
}
return newVal, nil

View File

@ -369,6 +369,54 @@ func TestProcessIgnoreChangesIndividual(t *testing.T) {
"b": cty.StringVal("new b value"),
}),
},
"null_map": {
cty.ObjectVal(map[string]cty.Value{
"a": cty.StringVal("ok"),
"list": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"s": cty.StringVal("ok"),
"map": cty.NullVal(cty.Map(cty.String)),
}),
}),
}),
cty.ObjectVal(map[string]cty.Value{
"a": cty.NullVal(cty.String),
"list": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"s": cty.StringVal("ok"),
"map": cty.NullVal(cty.Map(cty.String)),
}),
}),
}),
[]string{"a"},
cty.ObjectVal(map[string]cty.Value{
"a": cty.StringVal("ok"),
"list": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"s": cty.StringVal("ok"),
"map": cty.NullVal(cty.Map(cty.String)),
}),
}),
}),
},
"marked_map": {
cty.ObjectVal(map[string]cty.Value{
"map": cty.MapVal(map[string]cty.Value{
"key": cty.StringVal("val"),
}).Mark("marked"),
}),
cty.ObjectVal(map[string]cty.Value{
"map": cty.MapVal(map[string]cty.Value{
"key": cty.StringVal("new val"),
}).Mark("marked"),
}),
[]string{`map["key"]`},
cty.ObjectVal(map[string]cty.Value{
"map": cty.MapVal(map[string]cty.Value{
"key": cty.StringVal("val"),
}).Mark("marked"),
}),
},
}
for name, test := range tests {