github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/terraformrules/terraform_dash_in_resource_name_test.go (about) 1 package terraformrules 2 3 import ( 4 "testing" 5 6 hcl "github.com/hashicorp/hcl/v2" 7 "github.com/wata727/tflint/tflint" 8 ) 9 10 func Test_TerraformDashInResourceNameRule(t *testing.T) { 11 cases := []struct { 12 Name string 13 Content string 14 Expected tflint.Issues 15 }{ 16 { 17 Name: "dash in resource name", 18 Content: ` 19 resource "aws_eip" "dash-name" { 20 }`, 21 Expected: tflint.Issues{ 22 { 23 Rule: NewTerraformDashInResourceNameRule(), 24 Message: "`dash-name` resource name has a dash", 25 Range: hcl.Range{ 26 Filename: "resources.tf", 27 Start: hcl.Pos{Line: 2, Column: 1}, 28 End: hcl.Pos{Line: 2, Column: 31}, 29 }, 30 }, 31 }, 32 }, 33 { 34 Name: "no dash in resource name", 35 Content: ` 36 resource "aws_eip" "no_dash_name" { 37 }`, 38 Expected: tflint.Issues{}, 39 }, 40 } 41 42 rule := NewTerraformDashInResourceNameRule() 43 44 for _, tc := range cases { 45 runner := tflint.TestRunner(t, map[string]string{"resources.tf": tc.Content}) 46 47 if err := rule.Check(runner); err != nil { 48 t.Fatalf("Unexpected error occurred: %s", err) 49 } 50 51 tflint.AssertIssues(t, tc.Expected, runner.Issues) 52 } 53 }