github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/aws_route_specified_multiple_targets_test.go (about) 1 package awsrules 2 3 import ( 4 "testing" 5 6 hcl "github.com/hashicorp/hcl/v2" 7 "github.com/wata727/tflint/tflint" 8 ) 9 10 func Test_AwsRouteSpecifiedMultipleTargets(t *testing.T) { 11 cases := []struct { 12 Name string 13 Content string 14 Expected tflint.Issues 15 }{ 16 { 17 Name: "multiple route targets are specified", 18 Content: ` 19 resource "aws_route" "foo" { 20 route_table_id = "rtb-1234abcd" 21 gateway_id = "igw-1234abcd" 22 egress_only_gateway_id = "eigw-1234abcd" 23 }`, 24 Expected: tflint.Issues{ 25 { 26 Rule: NewAwsRouteSpecifiedMultipleTargetsRule(), 27 Message: "More than one routing target specified. It must be one.", 28 Range: hcl.Range{ 29 Filename: "resource.tf", 30 Start: hcl.Pos{Line: 2, Column: 1}, 31 End: hcl.Pos{Line: 2, Column: 27}, 32 }, 33 }, 34 }, 35 }, 36 { 37 Name: "single a route target is specified", 38 Content: ` 39 resource "aws_route" "foo" { 40 route_table_id = "rtb-1234abcd" 41 gateway_id = "igw-1234abcd" 42 }`, 43 Expected: tflint.Issues{}, 44 }, 45 { 46 Name: "multiple targes found, but the second one is null", 47 Content: ` 48 variable "egress_only_gateway_id" { 49 type = string 50 default = null 51 } 52 53 resource "aws_route" "foo" { 54 route_table_id = "rtb-1234abcd" 55 gateway_id = "igw-1234abcd" 56 egress_only_gateway_id = var.egress_only_gateway_id 57 }`, 58 Expected: tflint.Issues{}, 59 }, 60 } 61 62 rule := NewAwsRouteSpecifiedMultipleTargetsRule() 63 64 for _, tc := range cases { 65 runner := tflint.TestRunner(t, map[string]string{"resource.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 }