| 18 | ) |
| 19 | |
| 20 | func TestExpandedVariables(t *testing.T) { |
| 21 | fooSchema := &configschema.Block{ |
| 22 | Attributes: map[string]*configschema.Attribute{ |
| 23 | "foo": { |
| 24 | Type: cty.List(cty.Object(map[string]cty.Type{ |
| 25 | "bar": cty.String, |
| 26 | })), |
| 27 | Optional: true, |
| 28 | }, |
| 29 | "bar": { |
| 30 | Type: cty.Map(cty.String), |
| 31 | Optional: true, |
| 32 | }, |
| 33 | }, |
| 34 | } |
| 35 | |
| 36 | tests := map[string]struct { |
| 37 | src string |
| 38 | json bool |
| 39 | schema *configschema.Block |
| 40 | want []hcl.Traversal |
| 41 | }{ |
| 42 | "empty": { |
| 43 | src: ``, |
| 44 | schema: &configschema.Block{}, |
| 45 | want: nil, |
| 46 | }, |
| 47 | "attribute syntax": { |
| 48 | src: ` |
| 49 | foo = [ |
| 50 | { |
| 51 | bar = baz |
| 52 | }, |
| 53 | ] |
| 54 | `, |
| 55 | schema: fooSchema, |
| 56 | want: []hcl.Traversal{ |
| 57 | { |
| 58 | hcl.TraverseRoot{ |
| 59 | Name: "baz", |
| 60 | SrcRange: hcl.Range{ |
| 61 | Filename: "test.tf", |
| 62 | Start: hcl.Pos{Line: 4, Column: 11, Byte: 23}, |
| 63 | End: hcl.Pos{Line: 4, Column: 14, Byte: 26}, |
| 64 | }, |
| 65 | }, |
| 66 | }, |
| 67 | }, |
| 68 | }, |
| 69 | "block syntax": { |
| 70 | src: ` |
| 71 | foo { |
| 72 | bar = baz |
| 73 | } |
| 74 | `, |
| 75 | schema: fooSchema, |
| 76 | want: []hcl.Traversal{ |
| 77 | { |