github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/terraformrules/terraform_deprecated_index_test.go (about) 1 package terraformrules 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/hcl/v2" 7 "github.com/terraform-linters/tflint/tflint" 8 ) 9 10 func Test_TerraformDeprecatedIndexRule(t *testing.T) { 11 cases := []struct { 12 Name string 13 Content string 14 Expected tflint.Issues 15 }{ 16 { 17 Name: "deprecated dot index style", 18 Content: ` 19 locals { 20 list = ["a"] 21 value = list.0 22 } 23 `, 24 Expected: tflint.Issues{ 25 { 26 Rule: NewTerraformDeprecatedIndexRule(), 27 Message: "List items should be accessed using square brackets", 28 Range: hcl.Range{ 29 Filename: "config.tf", 30 Start: hcl.Pos{ 31 Line: 4, 32 Column: 11, 33 }, 34 End: hcl.Pos{ 35 Line: 4, 36 Column: 17, 37 }, 38 }, 39 }, 40 }, 41 }, 42 { 43 Name: "attribute access", 44 Content: ` 45 locals { 46 map = {a = "b"} 47 value = map.a 48 } 49 `, 50 Expected: tflint.Issues{}, 51 }, 52 { 53 Name: "fractional number", 54 Content: ` 55 locals { 56 value = 1.5 57 } 58 `, 59 Expected: tflint.Issues{}, 60 }, 61 } 62 63 rule := NewTerraformDeprecatedIndexRule() 64 65 for _, tc := range cases { 66 runner := tflint.TestRunner(t, map[string]string{"config.tf": tc.Content}) 67 68 if err := rule.Check(runner); err != nil { 69 t.Fatalf("Unexpected error occurred: %s", err) 70 } 71 72 tflint.AssertIssues(t, tc.Expected, runner.Issues) 73 } 74 }