Skip to content

Commit

Permalink
eval: add a test for a missing import (#248)
Browse files Browse the repository at this point in the history
Just what it says on the tin. Ensures that evaluation does not panic in
the case of a missing import.
  • Loading branch information
pgavlin authored Feb 6, 2024
1 parent 825d187 commit f987691
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ast/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (x *exprNode) Syntax() syntax.Node {

func exprPosition(expr Expr) (*hcl.Range, string) {
inner := reflect.ValueOf(expr)
if !inner.IsZero() {
if inner.IsValid() && !inner.IsZero() {
if syntax := expr.Syntax(); syntax != nil {
return syntax.Syntax().Range(), syntax.Syntax().Path()
}
Expand Down
2 changes: 1 addition & 1 deletion eval/testdata/eval/context-interpolation/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,4 @@
"evalJSONRevealed": {
"data": "TEST_ENVIRONMENT-USER_123"
}
}
}
4 changes: 4 additions & 0 deletions eval/testdata/eval/invalid-import/env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
imports:
-
values:
foo: bar
148 changes: 148 additions & 0 deletions eval/testdata/eval/invalid-import/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"loadDiags": [
{
"Severity": 1,
"Summary": "import must be a string or an object",
"Detail": "",
"Subject": {
"Filename": "invalid-import",
"Start": {
"Line": 2,
"Column": 4,
"Byte": 12
},
"End": {
"Line": 2,
"Column": 4,
"Byte": 12
}
},
"Context": null,
"Expression": null,
"EvalContext": null,
"Extra": null,
"Path": "imports[0]"
}
],
"check": {
"exprs": {
"foo": {
"range": {
"environment": "invalid-import",
"begin": {
"line": 4,
"column": 8,
"byte": 29
},
"end": {
"line": 4,
"column": 11,
"byte": 32
}
},
"schema": {
"type": "string",
"const": "bar"
},
"literal": "bar"
}
},
"properties": {
"foo": {
"value": "bar",
"trace": {
"def": {
"environment": "invalid-import",
"begin": {
"line": 4,
"column": 8,
"byte": 29
},
"end": {
"line": 4,
"column": 11,
"byte": 32
}
}
}
}
},
"schema": {
"properties": {
"foo": {
"type": "string",
"const": "bar"
}
},
"type": "object",
"required": [
"foo"
]
}
},
"checkJson": {
"foo": "bar"
},
"eval": {
"exprs": {
"foo": {
"range": {
"environment": "invalid-import",
"begin": {
"line": 4,
"column": 8,
"byte": 29
},
"end": {
"line": 4,
"column": 11,
"byte": 32
}
},
"schema": {
"type": "string",
"const": "bar"
},
"literal": "bar"
}
},
"properties": {
"foo": {
"value": "bar",
"trace": {
"def": {
"environment": "invalid-import",
"begin": {
"line": 4,
"column": 8,
"byte": 29
},
"end": {
"line": 4,
"column": 11,
"byte": 32
}
}
}
}
},
"schema": {
"properties": {
"foo": {
"type": "string",
"const": "bar"
}
},
"type": "object",
"required": [
"foo"
]
}
},
"evalJsonRedacted": {
"foo": "bar"
},
"evalJSONRevealed": {
"foo": "bar"
}
}

0 comments on commit f987691

Please sign in to comment.