(filename string)
| 40 | } |
| 41 | |
| 42 | func (r *Runner) LoadTestFile(filename string) (*TestFile, hcl.Diagnostics) { |
| 43 | f, diags := r.parser.ParseHCLFile(filename) |
| 44 | if diags.HasErrors() { |
| 45 | return nil, diags |
| 46 | } |
| 47 | |
| 48 | content, moreDiags := f.Body.Content(testFileSchema) |
| 49 | diags = append(diags, moreDiags...) |
| 50 | if moreDiags.HasErrors() { |
| 51 | return nil, diags |
| 52 | } |
| 53 | |
| 54 | ret := &TestFile{ |
| 55 | ResultType: cty.DynamicPseudoType, |
| 56 | } |
| 57 | |
| 58 | if typeAttr, exists := content.Attributes["result_type"]; exists { |
| 59 | ty, moreDiags := typeexpr.TypeConstraint(typeAttr.Expr) |
| 60 | diags = append(diags, moreDiags...) |
| 61 | if !moreDiags.HasErrors() { |
| 62 | ret.ResultType = ty |
| 63 | } |
| 64 | ret.ResultTypeRange = typeAttr.Expr.Range() |
| 65 | } |
| 66 | |
| 67 | if resultAttr, exists := content.Attributes["result"]; exists { |
| 68 | resultVal, moreDiags := resultAttr.Expr.Value(nil) |
| 69 | diags = append(diags, moreDiags...) |
| 70 | if !moreDiags.HasErrors() { |
| 71 | resultVal, err := convert.Convert(resultVal, ret.ResultType) |
| 72 | if err != nil { |
| 73 | diags = diags.Append(&hcl.Diagnostic{ |
| 74 | Severity: hcl.DiagError, |
| 75 | Summary: "Invalid result value", |
| 76 | Detail: fmt.Sprintf("The result value does not conform to the given result type: %s.", err), |
| 77 | Subject: resultAttr.Expr.Range().Ptr(), |
| 78 | }) |
| 79 | } else { |
| 80 | ret.Result = resultVal |
| 81 | } |
| 82 | } |
| 83 | ret.ResultRange = resultAttr.Expr.Range() |
| 84 | } |
| 85 | |
| 86 | for _, block := range content.Blocks { |
| 87 | switch block.Type { |
| 88 | |
| 89 | case "traversals": |
| 90 | if ret.ChecksTraversals { |
| 91 | // Indicates a duplicate traversals block |
| 92 | diags = diags.Append(&hcl.Diagnostic{ |
| 93 | Severity: hcl.DiagError, |
| 94 | Summary: "Duplicate \"traversals\" block", |
| 95 | Detail: "Only one traversals block is expected.", |
| 96 | Subject: &block.TypeRange, |
| 97 | }) |
| 98 | continue |
| 99 | } |
no test coverage detected