Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hcldec: A test case for attributes set to cty.DynamicVal with refinements #626

Merged
merged 1 commit into from
Aug 30, 2023
Merged
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
8 changes: 8 additions & 0 deletions hcldec/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func TestRefineValueSpec(t *testing.T) {
config := `
foo = "hello"
bar = unk
dyn = dyn
`

f, diags := hclsyntax.ParseConfig([]byte(config), "", hcl.InitialPos)
Expand Down Expand Up @@ -257,11 +258,13 @@ bar = unk
spec := &ObjectSpec{
"foo": attrSpec("foo"),
"bar": attrSpec("bar"),
"dyn": attrSpec("dyn"),
}

got, diags := Decode(f.Body, spec, &hcl.EvalContext{
Variables: map[string]cty.Value{
"unk": cty.UnknownVal(cty.String),
"dyn": cty.DynamicVal,
},
})
if diags.HasErrors() {
Expand All @@ -276,6 +279,11 @@ bar = unk

// The final value of bar is unknown but refined as non-null.
"bar": cty.UnknownVal(cty.String).RefineNotNull(),

// The final value of dyn is unknown but refined as non-null.
// Correct behavior here requires that we convert the DynamicVal
// to an unknown string first and then refine it.
"dyn": cty.UnknownVal(cty.String).RefineNotNull(),
})
if diff := cmp.Diff(want, got, ctydebug.CmpOptions); diff != "" {
t.Errorf("wrong result\n%s", diff)
Expand Down