File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
internal/lang/blocktoattr Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,8 @@ func (b *fixupBody) fixupContent(content *hcl.BodyContent) *hcl.BodyContent {
137137 NameRange : blocks [0 ].TypeRange ,
138138 }
139139 }
140+
141+ ret .MissingItemRange = b .MissingItemRange ()
140142 return & ret
141143}
142144
Original file line number Diff line number Diff line change @@ -360,6 +360,46 @@ container {
360360 }),
361361 }),
362362 },
363+
364+ "missing nested block items" : {
365+ src : `
366+ container {
367+ foo {
368+ bar = "one"
369+ }
370+ }
371+ ` ,
372+ schema : & configschema.Block {
373+ BlockTypes : map [string ]* configschema.NestedBlock {
374+ "container" : {
375+ Nesting : configschema .NestingList ,
376+ MinItems : 2 ,
377+ Block : configschema.Block {
378+ Attributes : map [string ]* configschema.Attribute {
379+ "foo" : {
380+ Type : cty .List (cty .Object (map [string ]cty.Type {
381+ "bar" : cty .String ,
382+ })),
383+ Optional : true ,
384+ },
385+ },
386+ },
387+ },
388+ },
389+ },
390+ want : cty .ObjectVal (map [string ]cty.Value {
391+ "container" : cty .ListVal ([]cty.Value {
392+ cty .ObjectVal (map [string ]cty.Value {
393+ "foo" : cty .ListVal ([]cty.Value {
394+ cty .ObjectVal (map [string ]cty.Value {
395+ "bar" : cty .StringVal ("baz" ),
396+ }),
397+ }),
398+ }),
399+ }),
400+ }),
401+ wantErrs : true ,
402+ },
363403 }
364404
365405 ctx := & hcl.EvalContext {
@@ -398,6 +438,14 @@ container {
398438 if ! diags .HasErrors () {
399439 t .Errorf ("succeeded, but want error\n got: %#v" , got )
400440 }
441+
442+ // check that our wrapped body returns the correct context by
443+ // verifying the Subject is valid.
444+ for _ , d := range diags {
445+ if d .Subject .Filename == "" {
446+ t .Errorf ("empty diagnostic subject: %#v" , d .Subject )
447+ }
448+ }
401449 return
402450 }
403451
You can’t perform that action at this time.
0 commit comments