Skip to content

Commit

Permalink
WIP - tests
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Nov 30, 2022
1 parent 9f07ba7 commit 05fb068
Showing 1 changed file with 119 additions and 0 deletions.
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

0 comments on commit 05fb068

Please sign in to comment.