don't add paths multiple times in PathsWithMark

PathsWithMark was adding the same path multiple times if it had multiple
extra marks.
pull/36619/head
James Bardin 1 year ago
parent ad6cbd6d7b
commit 64c68a0a45

@ -31,9 +31,12 @@ func PathsWithMark(pvms []cty.PathValueMarks, wantMark any) (withWanted []cty.Pa
if _, ok := pvm.Marks[wantMark]; ok {
withWanted = append(withWanted, pvm.Path)
}
for mark := range pvm.Marks {
if mark != wantMark {
withOthers = append(withOthers, pvm)
// only add a path with unwanted marks a single time
break
}
}
}

@ -16,7 +16,7 @@ func TestPathsWithMark(t *testing.T) {
input := []cty.PathValueMarks{
{
Path: cty.GetAttrPath("sensitive"),
Marks: cty.NewValueMarks(Sensitive),
Marks: cty.NewValueMarks("sensitive"),
},
{
Path: cty.GetAttrPath("other"),
@ -24,11 +24,15 @@ func TestPathsWithMark(t *testing.T) {
},
{
Path: cty.GetAttrPath("both"),
Marks: cty.NewValueMarks(Sensitive, "other"),
Marks: cty.NewValueMarks("sensitive", "other"),
},
{
Path: cty.GetAttrPath("neither"),
Marks: cty.NewValueMarks("x", "y"),
},
}
gotPaths, gotOthers := PathsWithMark(input, Sensitive)
gotPaths, gotOthers := PathsWithMark(input, "sensitive")
wantPaths := []cty.Path{
cty.GetAttrPath("sensitive"),
cty.GetAttrPath("both"),
@ -40,7 +44,7 @@ func TestPathsWithMark(t *testing.T) {
},
{
Path: cty.GetAttrPath("both"),
Marks: cty.NewValueMarks(Sensitive, "other"),
Marks: cty.NewValueMarks("sensitive", "other"),
// Note that this intentionally preserves the fact that the
// attribute was both sensitive _and_ had another mark, since
// that gives the caller the most possible information to
@ -48,6 +52,10 @@ func TestPathsWithMark(t *testing.T) {
// an error message, or whatever. It also conveniently avoids
// allocating a new mark set, which is nice.
},
{
Path: cty.GetAttrPath("neither"),
Marks: cty.NewValueMarks("x", "y"),
},
}
if diff := cmp.Diff(wantPaths, gotPaths, ctydebug.CmpOptions); diff != "" {

Loading…
Cancel
Save