Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/lang/funcs/sensitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ var IssensitiveFunc = function.New(&function.Spec{
return cty.Bool, nil
},
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
s := args[0].HasMark(marks.Sensitive)
return cty.BoolVal(s), nil
switch v := args[0]; {
case v.HasMark(marks.Sensitive):
return cty.True, nil
case !v.IsKnown():
return cty.UnknownVal(cty.Bool), nil
Comment on lines +74 to +77
Copy link
Copy Markdown
Contributor

@liamcervante liamcervante Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't lose marks going from unknown to known? Do we want to switch these case statements around?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I didn't read the PR description 😅

default:
return cty.False, nil
}
},
})

Expand Down
20 changes: 10 additions & 10 deletions internal/lang/funcs/sensitive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,47 +166,47 @@ func TestNonsensitive(t *testing.T) {
func TestIssensitive(t *testing.T) {
tests := []struct {
Input cty.Value
Sensitive bool
Sensitive cty.Value
WantErr string
}{
{
cty.NumberIntVal(1).Mark(marks.Sensitive),
true,
cty.True,
``,
},
{
cty.NumberIntVal(1),
false,
cty.False,
``,
},
{
cty.DynamicVal.Mark(marks.Sensitive),
true,
cty.True,
``,
},
{
cty.UnknownVal(cty.String).Mark(marks.Sensitive),
true,
cty.True,
``,
},
{
cty.NullVal(cty.EmptyObject).Mark(marks.Sensitive),
true,
cty.True,
``,
},
{
cty.NullVal(cty.String),
false,
cty.False,
``,
},
{
cty.DynamicVal,
false,
cty.UnknownVal(cty.Bool),
``,
},
{
cty.UnknownVal(cty.String),
false,
cty.UnknownVal(cty.Bool),
``,
},
}
Expand All @@ -227,7 +227,7 @@ func TestIssensitive(t *testing.T) {
t.Fatalf("unexpected error: %s", err)
}

if (got.True() && !test.Sensitive) || (got.False() && test.Sensitive) {
if !got.RawEquals(test.Sensitive) {
t.Errorf("wrong result \ngot: %#v\nwant: %#v", got, test.Sensitive)
}
})
Expand Down