@@ -1695,6 +1695,7 @@ func TestCompletionAtPos_BodySchema_Extensions_DynamicBlock(t *testing.T) {
1695
1695
cfg string
1696
1696
pos hcl.Pos
1697
1697
expectedCandidates lang.Candidates
1698
+ expectedErr string
1698
1699
}{
1699
1700
{
1700
1701
"dynamic block does not complete if not enabled" ,
@@ -1728,6 +1729,7 @@ resource "aws_elastic_beanstalk_environment" "example" {
1728
1729
Byte : 77 ,
1729
1730
},
1730
1731
lang .CompleteCandidates ([]lang.Candidate {}),
1732
+ "" ,
1731
1733
},
1732
1734
{
1733
1735
"dynamic block does not complete without blocks" ,
@@ -1783,6 +1785,7 @@ resource "aws_elastic_beanstalk_environment" "example" {
1783
1785
Kind : lang .AttributeCandidateKind ,
1784
1786
},
1785
1787
}),
1788
+ "" ,
1786
1789
},
1787
1790
{
1788
1791
"dynamic block completion" ,
@@ -1878,6 +1881,7 @@ resource "aws_elastic_beanstalk_environment" "example" {
1878
1881
},
1879
1882
},
1880
1883
}),
1884
+ "" ,
1881
1885
},
1882
1886
{
1883
1887
"dynamic block inner completion" ,
@@ -2001,6 +2005,7 @@ resource "aws_elastic_beanstalk_environment" "example" {
2001
2005
},
2002
2006
},
2003
2007
}),
2008
+ "" ,
2004
2009
},
2005
2010
{
2006
2011
"dynamic block content attribute completion" ,
@@ -2074,6 +2079,7 @@ resource "aws_elastic_beanstalk_environment" "example" {
2074
2079
},
2075
2080
},
2076
2081
}),
2082
+ "" ,
2077
2083
},
2078
2084
{
2079
2085
"dynamic block label only completes dependent blocks" ,
@@ -2136,6 +2142,52 @@ resource "aws_elastic_beanstalk_environment" "example" {
2136
2142
},
2137
2143
},
2138
2144
}),
2145
+ "" ,
2146
+ },
2147
+ {
2148
+ "dynamic block label never completes static blocks" ,
2149
+ & schema.BodySchema {
2150
+ Blocks : map [string ]* schema.BlockSchema {
2151
+ "resource" : {
2152
+ Labels : []* schema.LabelSchema {
2153
+ {
2154
+ Name : "type" ,
2155
+ IsDepKey : true ,
2156
+ Completable : true ,
2157
+ },
2158
+ {Name : "name" },
2159
+ },
2160
+ Body : & schema.BodySchema {
2161
+ Extensions : & schema.BodyExtensions {
2162
+ DynamicBlocks : true ,
2163
+ },
2164
+ Blocks : map [string ]* schema.BlockSchema {
2165
+ "lifecycle" : {
2166
+ Body : schema .NewBodySchema (),
2167
+ },
2168
+ },
2169
+ },
2170
+ DependentBody : map [schema.SchemaKey ]* schema.BodySchema {
2171
+ schema .NewSchemaKey (schema.DependencyKeys {
2172
+ Labels : []schema.LabelDependent {
2173
+ {Index : 0 , Value : "aws_instance" },
2174
+ },
2175
+ }): {
2176
+ Blocks : make (map [string ]* schema.BlockSchema , 0 ),
2177
+ },
2178
+ },
2179
+ },
2180
+ },
2181
+ },
2182
+ `resource "aws_instance" "example" {
2183
+ name = "example"
2184
+ dynamic "" {
2185
+
2186
+ }
2187
+ }` ,
2188
+ hcl.Pos {Line : 3 , Column : 12 , Byte : 66 },
2189
+ lang .CompleteCandidates ([]lang.Candidate {}),
2190
+ `test.tf (3,12): unknown block type "dynamic"` ,
2139
2191
},
2140
2192
// completion nesting should work
2141
2193
{
@@ -2245,6 +2297,7 @@ resource "aws_elastic_beanstalk_environment" "example" {
2245
2297
},
2246
2298
},
2247
2299
}),
2300
+ "" ,
2248
2301
},
2249
2302
// completion after the thing =
2250
2303
{
@@ -2333,6 +2386,7 @@ resource "aws_elastic_beanstalk_environment" "example" {
2333
2386
},
2334
2387
},
2335
2388
}),
2389
+ "" ,
2336
2390
},
2337
2391
// check allows more than one dynamic
2338
2392
{
@@ -2409,6 +2463,7 @@ resource "aws_elastic_beanstalk_environment" "example" {
2409
2463
},
2410
2464
},
2411
2465
}),
2466
+ "" ,
2412
2467
},
2413
2468
// allows dynamic blocks in blocks
2414
2469
{
@@ -2496,6 +2551,7 @@ resource "aws_elastic_beanstalk_environment" "example" {
2496
2551
},
2497
2552
},
2498
2553
}),
2554
+ "" ,
2499
2555
},
2500
2556
// never complete dynamic as a dynamic label
2501
2557
{
@@ -2562,6 +2618,7 @@ resource "aws_elastic_beanstalk_environment" "example" {
2562
2618
},
2563
2619
},
2564
2620
}),
2621
+ "" ,
2565
2622
},
2566
2623
}
2567
2624
@@ -2576,14 +2633,17 @@ resource "aws_elastic_beanstalk_environment" "example" {
2576
2633
},
2577
2634
})
2578
2635
2579
- // We're triggering completion twice her, to cover any unintended side effects
2580
- _ , err := d .CandidatesAtPos (ctx , "test.tf" , tc .pos )
2581
- if err != nil {
2582
- t .Fatal (err )
2583
- }
2584
2636
candidates , err := d .CandidatesAtPos (ctx , "test.tf" , tc .pos )
2637
+
2585
2638
if err != nil {
2586
- t .Fatal (err )
2639
+ if tc .expectedErr != "" && err .Error () != tc .expectedErr {
2640
+ t .Fatalf ("unexpected error: %q\n expected: %q\n " ,
2641
+ err , tc .expectedErr )
2642
+ } else if tc .expectedErr == "" {
2643
+ t .Fatal (err )
2644
+ }
2645
+ } else if tc .expectedErr != "" {
2646
+ t .Fatalf ("expected error: %q" , tc .expectedErr )
2587
2647
}
2588
2648
2589
2649
if diff := cmp .Diff (tc .expectedCandidates , candidates ); diff != "" {
0 commit comments