Skip to content

Commit

Permalink
ext: TryFunc tests to document handling of marked values
Browse files Browse the repository at this point in the history
  • Loading branch information
mildwonkey committed Apr 22, 2021
1 parent f601991 commit ea1c034
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ext/tryfunc/tryfunc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func TestTryFunc(t *testing.T) {
cty.NumberIntVal(1),
``,
},
"one marked argument succeeds": {
`try(sensitive)`,
map[string]cty.Value{
"sensitive": cty.StringVal("secret").Mark("porpoise"),
},
cty.StringVal("secret").Mark("porpoise"),
``,
},
"two arguments, first succeeds": {
`try(1, 2)`,
nil,
Expand Down Expand Up @@ -66,6 +74,36 @@ func TestTryFunc(t *testing.T) {
cty.DynamicVal, // can't proceed until first argument is wholly known
``,
},
"two arguments, both marked, first succeeds": {
`try(sensitive, other)`,
map[string]cty.Value{
"sensitive": cty.StringVal("secret").Mark("porpoise"),
"other": cty.StringVal("that").Mark("a"),
},
cty.StringVal("secret").Mark("porpoise"),
``,
},
"two arguments, both marked, second succeeds": {
`try(sensitive, other)`,
map[string]cty.Value{
"other": cty.StringVal("that").Mark("a"),
},
cty.StringVal("that").Mark("a"),
``,
},
"two arguments, result is element of marked list ": {
`try(sensitive[0], other)`,
map[string]cty.Value{
"sensitive": cty.ListVal([]cty.Value{
cty.StringVal("list"),
cty.StringVal("of "),
cty.StringVal("secrets"),
}).Mark("secret"),
"other": cty.StringVal("not"),
},
cty.StringVal("list").Mark("secret"),
``,
},
"three arguments, all fail": {
`try(this, that, this_thing_in_particular)`,
nil,
Expand Down

0 comments on commit ea1c034

Please sign in to comment.