Skip to content
Draft
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
119 changes: 119 additions & 0 deletions decoder/reference_origins_collect_hcl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,125 @@ tup = [ var.three ]
},
},
},
{
"cyclical origin referring back to the attribute",
&schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"attr": {
Address: &schema.AttributeAddrSchema{
Steps: schema.Address{
schema.StaticStep{Name: "root"},
schema.AttrNameStep{},
},
},
IsOptional: true,
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
},
},
},
`attr = root.attr`,
reference.Origins{},
},
{
"cyclical origin referring back to the attribute with implied address",
&schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{
"blk": {
Address: &schema.BlockAddrSchema{
Steps: schema.Address{
schema.StaticStep{Name: "blk"},
},
BodyAsData: true,
InferBody: true,
},
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"attr": {
IsOptional: true,
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
},
},
},
},
},
},
`blk {
attr = blk.attr
}
`,
reference.Origins{},
},
{
"cyclical origin referring back to the block with implied address",
&schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{
"blk": {
Address: &schema.BlockAddrSchema{
Steps: schema.Address{
schema.StaticStep{Name: "blk"},
},
BodyAsData: true,
InferBody: true,
},
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"attr": {
IsOptional: true,
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
},
},
},
},
},
},
`blk {
attr = blk
}
`,
reference.Origins{},
},
{
"cyclical origin referring to another attribute in the same the block",
&schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{
"blk": {
Address: &schema.BlockAddrSchema{
Steps: schema.Address{
schema.StaticStep{Name: "blk"},
},
BodyAsData: true,
InferBody: true,
},
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"attr": {
IsOptional: true,
Expr: schema.ExprConstraints{
schema.TraversalExpr{OfType: cty.String},
schema.LiteralTypeExpr{Type: cty.String},
},
},
},
},
},
},
},
`blk {
foo = "test"
attr = blk.foo
}
`,
reference.Origins{},
},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("%d/%s", i, tc.name), func(t *testing.T) {
Expand Down