github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/pattern_rule_test.go.tmpl (about) 1 // This file generated by `tools/model-rule-gen/main.go`. DO NOT EDIT 2 3 package models 4 5 import ( 6 "testing" 7 8 "github.com/wata727/tflint/tflint" 9 ) 10 11 func Test_{{ .RuleNameCC }}Rule(t *testing.T) { 12 cases := []struct { 13 Name string 14 Content string 15 Expected tflint.Issues 16 }{ 17 { 18 Name: "It includes invalid characters", 19 Content: ` 20 resource "{{ .ResourceType }}" "foo" { 21 {{ .AttributeName }} = {{ .TestNG }} 22 }`, 23 Expected: tflint.Issues{ 24 { 25 Rule: New{{ .RuleNameCC }}Rule(), 26 {{- if ne .Pattern "" }} 27 Message: `{{ .AttributeName }} does not match valid pattern {{ .Pattern }}`, 28 {{- end }} 29 {{- if ne (len .Enum) 0 }} 30 Message: `{{ .AttributeName }} is not a valid value`, 31 {{- end }} 32 }, 33 }, 34 }, 35 { 36 Name: "It is valid", 37 Content: ` 38 resource "{{ .ResourceType }}" "foo" { 39 {{ .AttributeName }} = {{ .TestOK }} 40 }`, 41 Expected: tflint.Issues{}, 42 }, 43 } 44 45 rule := New{{ .RuleNameCC }}Rule() 46 47 for _, tc := range cases { 48 runner := tflint.TestRunner(t, map[string]string{"resource.tf": tc.Content}) 49 50 if err := rule.Check(runner); err != nil { 51 t.Fatalf("Unexpected error occurred: %s", err) 52 } 53 54 tflint.AssertIssuesWithoutRange(t, tc.Expected, runner.Issues) 55 } 56 }