diff --git a/decoder/body_candidates_test.go b/decoder/body_candidates_test.go index 68be8aca..e36e6d61 100644 --- a/decoder/body_candidates_test.go +++ b/decoder/body_candidates_test.go @@ -1,6 +1,7 @@ package decoder import ( + "context" "testing" "github.com/google/go-cmp/cmp" @@ -12,6 +13,7 @@ import ( ) func TestDecoder_CandidateAtPos_incompleteAttributes(t *testing.T) { + ctx := context.Background() bodySchema := &schema.BodySchema{ Blocks: map[string]*schema.BlockSchema{ "customblock": { @@ -43,7 +45,7 @@ func TestDecoder_CandidateAtPos_incompleteAttributes(t *testing.T) { }) d.maxCandidates = 1 - candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{ + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{ Line: 2, Column: 7, Byte: 29, @@ -84,6 +86,7 @@ func TestDecoder_CandidateAtPos_incompleteAttributes(t *testing.T) { } func TestDecoder_CandidateAtPos_computedAttributes(t *testing.T) { + ctx := context.Background() bodySchema := &schema.BodySchema{ Blocks: map[string]*schema.BlockSchema{ "customblock": { @@ -113,7 +116,7 @@ func TestDecoder_CandidateAtPos_computedAttributes(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{ + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{ Line: 2, Column: 7, Byte: 29, @@ -154,6 +157,7 @@ func TestDecoder_CandidateAtPos_computedAttributes(t *testing.T) { } func TestDecoder_CandidateAtPos_incompleteBlocks(t *testing.T) { + ctx := context.Background() bodySchema := &schema.BodySchema{ Blocks: map[string]*schema.BlockSchema{ "customblock": { @@ -186,7 +190,7 @@ func TestDecoder_CandidateAtPos_incompleteBlocks(t *testing.T) { }) d.maxCandidates = 1 - candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{ + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{ Line: 3, Column: 8, Byte: 42, @@ -227,6 +231,7 @@ func TestDecoder_CandidateAtPos_incompleteBlocks(t *testing.T) { } func TestDecoder_CandidateAtPos_duplicateNames(t *testing.T) { + ctx := context.Background() bodySchema := &schema.BodySchema{ Attributes: map[string]*schema.AttributeSchema{ "ingress": { @@ -258,7 +263,7 @@ func TestDecoder_CandidateAtPos_duplicateNames(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", hcl.InitialPos) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.InitialPos) if err != nil { t.Fatal(err) } diff --git a/decoder/candidates_test.go b/decoder/candidates_test.go index 79733a9e..5e5ffa2a 100644 --- a/decoder/candidates_test.go +++ b/decoder/candidates_test.go @@ -1,6 +1,7 @@ package decoder import ( + "context" "errors" "fmt" "strings" @@ -17,6 +18,7 @@ import ( ) func TestDecoder_CandidatesAtPos_noSchema(t *testing.T) { + ctx := context.Background() f, pDiags := hclsyntax.ParseConfig(testConfig, "test.tf", hcl.InitialPos) if len(pDiags) > 0 { t.Fatal(pDiags) @@ -28,7 +30,7 @@ func TestDecoder_CandidatesAtPos_noSchema(t *testing.T) { }, }) - _, err := d.CandidatesAtPos("test.tf", hcl.InitialPos) + _, err := d.CandidatesAtPos(ctx, "test.tf", hcl.InitialPos) noSchemaErr := &NoSchemaError{} if !errors.As(err, &noSchemaErr) { t.Fatal("expected NoSchemaError for no schema") @@ -36,6 +38,7 @@ func TestDecoder_CandidatesAtPos_noSchema(t *testing.T) { } func TestDecoder_CandidatesAtPos_emptyBody(t *testing.T) { + ctx := context.Background() f := &hcl.File{ Body: hcl.EmptyBody(), } @@ -46,7 +49,7 @@ func TestDecoder_CandidatesAtPos_emptyBody(t *testing.T) { }, }) - _, err := d.CandidatesAtPos("test.tf", hcl.InitialPos) + _, err := d.CandidatesAtPos(ctx, "test.tf", hcl.InitialPos) unknownFormatErr := &UnknownFileFormatError{} if !errors.As(err, &unknownFormatErr) { t.Fatal("expected UnknownFileFormatError for empty body") @@ -54,6 +57,7 @@ func TestDecoder_CandidatesAtPos_emptyBody(t *testing.T) { } func TestDecoder_CandidatesAtPos_json(t *testing.T) { + ctx := context.Background() f, pDiags := json.Parse([]byte(`{ "customblock": { "label1": {} @@ -69,7 +73,7 @@ func TestDecoder_CandidatesAtPos_json(t *testing.T) { }, }) - _, err := d.CandidatesAtPos("test.tf.json", hcl.InitialPos) + _, err := d.CandidatesAtPos(ctx, "test.tf.json", hcl.InitialPos) unknownFormatErr := &UnknownFileFormatError{} if !errors.As(err, &unknownFormatErr) { t.Fatal("expected UnknownFileFormatError for JSON body") @@ -77,6 +81,7 @@ func TestDecoder_CandidatesAtPos_json(t *testing.T) { } func TestDecoder_CandidatesAtPos_unknownBlock(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type"}, {Name: "name"}, @@ -110,7 +115,7 @@ func TestDecoder_CandidatesAtPos_unknownBlock(t *testing.T) { }, }) - _, err := d.CandidatesAtPos("test.tf", hcl.Pos{ + _, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{ Line: 2, Column: 1, Byte: 23, @@ -124,6 +129,7 @@ func TestDecoder_CandidatesAtPos_unknownBlock(t *testing.T) { } func TestDecoder_CandidatesAtPos_nilBodySchema(t *testing.T) { + ctx := context.Background() testCases := []struct { name string rootSchema *schema.BodySchema @@ -278,7 +284,7 @@ func TestDecoder_CandidatesAtPos_nilBodySchema(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", tc.pos) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", tc.pos) if err != nil { t.Fatal(err) } @@ -291,6 +297,7 @@ func TestDecoder_CandidatesAtPos_nilBodySchema(t *testing.T) { } func TestDecoder_CandidatesAtPos_prefixNearEOF(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type"}, {Name: "name"}, @@ -318,7 +325,7 @@ func TestDecoder_CandidatesAtPos_prefixNearEOF(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{ + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{ Line: 1, Column: 4, Byte: 3, @@ -356,6 +363,7 @@ func TestDecoder_CandidatesAtPos_prefixNearEOF(t *testing.T) { } func TestDecoder_CandidatesAtPos_invalidBlockPositions(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type"}, } @@ -420,7 +428,7 @@ func TestDecoder_CandidatesAtPos_invalidBlockPositions(t *testing.T) { for i, tc := range testCases { t.Run(fmt.Sprintf("%d-%s", i, tc.name), func(t *testing.T) { - _, err := d.CandidatesAtPos("test.tf", tc.pos) + _, err := d.CandidatesAtPos(ctx, "test.tf", tc.pos) if err == nil { t.Fatal("expected error") } @@ -432,6 +440,7 @@ func TestDecoder_CandidatesAtPos_invalidBlockPositions(t *testing.T) { } func TestDecoder_CandidatesAtPos_rightHandSide(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type"}, } @@ -463,7 +472,7 @@ func TestDecoder_CandidatesAtPos_rightHandSide(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{ + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{ Line: 2, Column: 13, Byte: 28, @@ -478,6 +487,7 @@ func TestDecoder_CandidatesAtPos_rightHandSide(t *testing.T) { } func TestDecoder_CandidatesAtPos_rightHandSideInString(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type"}, } @@ -509,7 +519,7 @@ func TestDecoder_CandidatesAtPos_rightHandSideInString(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{ + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{ Line: 2, Column: 15, Byte: 30, @@ -524,6 +534,7 @@ func TestDecoder_CandidatesAtPos_rightHandSideInString(t *testing.T) { } func TestDecoder_CandidatesAtPos_endOfLabel(t *testing.T) { + ctx := context.Background() blockSchema := &schema.BlockSchema{ Labels: []*schema.LabelSchema{ {Name: "type", Completable: true}, @@ -570,7 +581,7 @@ func TestDecoder_CandidatesAtPos_endOfLabel(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{ + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{ Line: 1, Column: 12, Byte: 11, @@ -628,6 +639,7 @@ func TestDecoder_CandidatesAtPos_endOfLabel(t *testing.T) { } func TestDecoder_CandidatesAtPos_nonCompletableLabel(t *testing.T) { + ctx := context.Background() blockSchema := &schema.BlockSchema{ Labels: []*schema.LabelSchema{ {Name: "type", IsDepKey: true}, @@ -663,7 +675,7 @@ func TestDecoder_CandidatesAtPos_nonCompletableLabel(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{ + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{ Line: 1, Column: 10, Byte: 9, @@ -678,6 +690,7 @@ func TestDecoder_CandidatesAtPos_nonCompletableLabel(t *testing.T) { } func TestDecoder_CandidatesAtPos_zeroByteContent(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type", IsDepKey: true, Completable: true}, {Name: "name"}, @@ -708,7 +721,7 @@ func TestDecoder_CandidatesAtPos_zeroByteContent(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", hcl.InitialPos) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.InitialPos) if err != nil { t.Fatal(err) } @@ -735,6 +748,7 @@ func TestDecoder_CandidatesAtPos_zeroByteContent(t *testing.T) { } func TestDecoder_CandidatesAtPos_endOfFilePos(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type", IsDepKey: true, Completable: true}, {Name: "name"}, @@ -770,7 +784,7 @@ func TestDecoder_CandidatesAtPos_endOfFilePos(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{Line: 4, Column: 1, Byte: 52}) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{Line: 4, Column: 1, Byte: 52}) if err != nil { t.Fatal(err) } @@ -800,6 +814,7 @@ func TestDecoder_CandidatesAtPos_endOfFilePos(t *testing.T) { } func TestDecoder_CandidatesAtPos_emptyLabel(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type", IsDepKey: true, Completable: true}, {Name: "name"}, @@ -857,7 +872,7 @@ func TestDecoder_CandidatesAtPos_emptyLabel(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{Line: 1, Column: 11, Byte: 10}) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{Line: 1, Column: 11, Byte: 10}) if err != nil { t.Fatal(err) } @@ -895,6 +910,7 @@ func TestDecoder_CandidatesAtPos_emptyLabel(t *testing.T) { } func TestDecoder_CandidatesAtPos_emptyLabel_duplicateDepKeys(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type", IsDepKey: true, Completable: true}, {Name: "name"}, @@ -963,7 +979,7 @@ func TestDecoder_CandidatesAtPos_emptyLabel_duplicateDepKeys(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{Line: 1, Column: 11, Byte: 10}) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{Line: 1, Column: 11, Byte: 10}) if err != nil { t.Fatal(err) } @@ -988,6 +1004,7 @@ func TestDecoder_CandidatesAtPos_emptyLabel_duplicateDepKeys(t *testing.T) { } func TestDecoder_CandidatesAtPos_basic(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type", IsDepKey: true, Completable: true}, {Name: "name"}, @@ -1294,7 +1311,7 @@ resource "random_resource" "test" { for i, tc := range testCases { t.Run(fmt.Sprintf("%d-%s", i, tc.name), func(t *testing.T) { - candidates, err := d.CandidatesAtPos("test.tf", tc.pos) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", tc.pos) if err != nil { t.Fatal(err) } @@ -1309,6 +1326,7 @@ resource "random_resource" "test" { } func TestDecoder_CandidatesAtPos_AnyAttribute(t *testing.T) { + ctx := context.Background() providersSchema := &schema.BlockSchema{ Body: &schema.BodySchema{ AnyAttribute: &schema.AttributeSchema{ @@ -1344,7 +1362,7 @@ func TestDecoder_CandidatesAtPos_AnyAttribute(t *testing.T) { }) pos := hcl.Pos{Line: 2, Column: 1, Byte: 21} - candidates, err := d.CandidatesAtPos("test.tf", pos) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", pos) if err != nil { t.Fatal(err) } @@ -1372,6 +1390,7 @@ func TestDecoder_CandidatesAtPos_AnyAttribute(t *testing.T) { } func TestDecoder_CandidatesAtPos_multipleTypes(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type", IsDepKey: true, Completable: true}, {Name: "name"}, @@ -1416,7 +1435,7 @@ func TestDecoder_CandidatesAtPos_multipleTypes(t *testing.T) { }) pos := hcl.Pos{Line: 2, Column: 1, Byte: 38} - candidates, err := d.CandidatesAtPos("test.tf", pos) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", pos) if err != nil { t.Fatal(err) } @@ -1444,6 +1463,7 @@ func TestDecoder_CandidatesAtPos_multipleTypes(t *testing.T) { } func TestDecoder_CandidatesAtPos_incompleteAttrOrBlock(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type"}, {Name: "name"}, @@ -1531,7 +1551,7 @@ resource "any" "ref" { }, }) - candidates, err := d.CandidatesAtPos("test.tf", tc.pos) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", tc.pos) if err != nil { t.Fatal(err) } @@ -1546,6 +1566,7 @@ resource "any" "ref" { } func TestDecoder_CandidatesAtPos_incompleteLabel(t *testing.T) { + ctx := context.Background() resourceLabelSchema := []*schema.LabelSchema{ {Name: "type"}, {Name: "name"}, @@ -1645,7 +1666,7 @@ resource "any" "ref" { }, }) - candidates, err := d.CandidatesAtPos("test.tf", tc.pos) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", tc.pos) if err != nil { t.Fatal(err) } diff --git a/decoder/expression_candidates_test.go b/decoder/expression_candidates_test.go index 27b44d89..e9a19f21 100644 --- a/decoder/expression_candidates_test.go +++ b/decoder/expression_candidates_test.go @@ -1,6 +1,7 @@ package decoder import ( + "context" "fmt" "testing" @@ -15,6 +16,7 @@ import ( ) func TestDecoder_CandidateAtPos_expressions(t *testing.T) { + ctx := context.Background() testCases := []struct { testName string attrSchema map[string]*schema.AttributeSchema @@ -1518,7 +1520,7 @@ func TestDecoder_CandidateAtPos_expressions(t *testing.T) { }, }) - candidates, err := d.CandidatesAtPos("test.tf", tc.pos) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", tc.pos) if err != nil { t.Fatal(err) } @@ -1531,6 +1533,7 @@ func TestDecoder_CandidateAtPos_expressions(t *testing.T) { } func TestDecoder_CandidateAtPos_traversalExpressions(t *testing.T) { + ctx := context.Background() testCases := []struct { testName string bodySchema *schema.BodySchema @@ -2556,7 +2559,7 @@ another_block "meh" { dirReader.paths[testDir].ReferenceTargets = append(dirReader.paths[testDir].ReferenceTargets, refTargets...) - candidates, err := d.CandidatesAtPos("test.tf", tc.pos) + candidates, err := d.CandidatesAtPos(ctx, "test.tf", tc.pos) if err != nil { t.Fatal(err) } @@ -2569,6 +2572,7 @@ another_block "meh" { } func TestDecoder_CandidateAtPos_expressions_crossFileTraversal(t *testing.T) { + ctx := context.Background() f1, _ := hclsyntax.ParseConfig([]byte(`variable "aaa" {} variable "bbb" {} variable "ccc" {} @@ -2685,7 +2689,7 @@ variable "ccc" {} dirReader.paths[testDir].ReferenceTargets = refTargets - candidates, err := d.CandidatesAtPos("test2.tf", hcl.Pos{ + candidates, err := d.CandidatesAtPos(ctx, "test2.tf", hcl.Pos{ Line: 1, Column: 9, Byte: 8, diff --git a/decoder/label_candidates_test.go b/decoder/label_candidates_test.go index bb12e270..d4afa7de 100644 --- a/decoder/label_candidates_test.go +++ b/decoder/label_candidates_test.go @@ -1,6 +1,7 @@ package decoder import ( + "context" "testing" "github.com/google/go-cmp/cmp" @@ -12,6 +13,7 @@ import ( ) func TestDecoder_CandidateAtPos_incompleteLabels(t *testing.T) { + ctx := context.Background() bodySchema := &schema.BodySchema{ Blocks: map[string]*schema.BlockSchema{ "customblock": { @@ -64,7 +66,7 @@ func TestDecoder_CandidateAtPos_incompleteLabels(t *testing.T) { }) d.maxCandidates = 1 - candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{ + candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{ Line: 1, Column: 14, Byte: 13, @@ -104,6 +106,7 @@ func TestDecoder_CandidateAtPos_incompleteLabels(t *testing.T) { } func TestCandidatesAtPos_prefillRequiredFields(t *testing.T) { + ctx := context.Background() startingConfig := "resource \"\" {\n}" startingPos := hcl.Pos{ Line: 1, @@ -614,7 +617,7 @@ func TestCandidatesAtPos_prefillRequiredFields(t *testing.T) { d.maxCandidates = 1 d.PrefillRequiredFields = tt.prefill - got, err := d.CandidatesAtPos("test.tf", startingPos) + got, err := d.CandidatesAtPos(ctx, "test.tf", startingPos) if err != nil { t.Fatal(err) }