github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/terraformrules/terraform_documented_variables_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_TerraformDocumentedVariablesRule(t *testing.T) { 11 cases := []struct { 12 Name string 13 Content string 14 Expected tflint.Issues 15 }{ 16 { 17 Name: "no description", 18 Content: ` 19 variable "no_description" { 20 default = "default" 21 }`, 22 Expected: tflint.Issues{ 23 { 24 Rule: NewTerraformDocumentedVariablesRule(), 25 Message: "`no_description` variable has no description", 26 Range: hcl.Range{ 27 Filename: "variables.tf", 28 Start: hcl.Pos{Line: 2, Column: 1}, 29 End: hcl.Pos{Line: 2, Column: 26}, 30 }, 31 }, 32 }, 33 }, 34 { 35 Name: "empty description", 36 Content: ` 37 variable "empty_description" { 38 description = "" 39 }`, 40 Expected: tflint.Issues{ 41 { 42 Rule: NewTerraformDocumentedVariablesRule(), 43 Message: "`empty_description` variable has no description", 44 Range: hcl.Range{ 45 Filename: "variables.tf", 46 Start: hcl.Pos{Line: 2, Column: 1}, 47 End: hcl.Pos{Line: 2, Column: 29}, 48 }, 49 }, 50 }, 51 }, 52 { 53 Name: "with description", 54 Content: ` 55 variable "with_description" { 56 description = "This is description" 57 }`, 58 Expected: tflint.Issues{}, 59 }, 60 } 61 62 rule := NewTerraformDocumentedVariablesRule() 63 64 for _, tc := range cases { 65 runner := tflint.TestRunner(t, map[string]string{"variables.tf": tc.Content}) 66 67 if err := rule.Check(runner); err != nil { 68 t.Fatalf("Unexpected error occurred: %s", err) 69 } 70 71 tflint.AssertIssues(t, tc.Expected, runner.Issues) 72 } 73 }