Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test case for panics for invalid namespaced function expressions #383

Merged
merged 6 commits into from
Apr 5, 2024
Next Next commit
test: add test case for hover for panics for invalid namespaced funct…
…ion expressions
  • Loading branch information
ansgarm authored and dbanck committed Mar 26, 2024
commit 67ff22b74b6f2848e9e1e698e5f9c963f1eb3b2b
28 changes: 28 additions & 0 deletions decoder/hover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,34 @@ func TestDecoder_HoverAtPos_basic(t *testing.T) {
}
}

func TestDecoder_HoverAtPos_nil_expr(t *testing.T) {
// provider:: is not a traversal expression, so hcl will return a ExprSyntaxError which needs to be handled
f, _ := hclsyntax.ParseConfig([]byte(`attr = provider::`), "test.tf", hcl.InitialPos)

d := testPathDecoder(t, &PathContext{
Schema: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"attr": {Constraint: schema.AnyExpression{OfType: cty.DynamicPseudoType}},
},
},
Files: map[string]*hcl.File{
"test.tf": f,
},
})

ctx := context.Background()
_, err := d.HoverAtPos(ctx, "test.tf", hcl.Pos{Line: 1, Column: 16, Byte: 15})

if err == nil {
t.Fatal("expected error")
}

positionalErr := &PositionalError{}
if !errors.As(err, &positionalErr) {
t.Fatal("expected PositionalError for invalid expression")
}
}

func TestDecoder_HoverAtPos_URL(t *testing.T) {
resourceLabelSchema := []*schema.LabelSchema{
{Name: "type", IsDepKey: true},
Expand Down