generated from terraform-linters/tflint-ruleset-template
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathaws_security_group_rule_invalid_protocol_test.go
66 lines (59 loc) · 1.32 KB
/
aws_security_group_rule_invalid_protocol_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package rules
import (
"testing"
hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/helper"
)
func Test_AwsSecurityGroupRuleInvalidProtocol(t *testing.T) {
cases := []struct {
Name string
Content string
Expected helper.Issues
}{
{
Name: "valid protocol",
Content: `
resource "aws_security_group_rule" "this" {
protocol = "tcp"
}
`,
Expected: helper.Issues{},
},
{
Name: "valid number as protocol",
Content: `
resource "aws_security_group_rule" "this" {
protocol = "-1"
}
`,
Expected: helper.Issues{},
},
{
Name: "invalid protocol",
Content: `
resource "aws_security_group_rule" "this" {
protocol = "http"
}
`,
Expected: helper.Issues{
{
Rule: NewAwsSecurityGroupRuleInvalidProtocolRule(),
Message: "\"http\" is an invalid protocol.",
Range: hcl.Range{
Filename: "resource.tf",
Start: hcl.Pos{Line: 3, Column: 16},
End: hcl.Pos{Line: 3, Column: 22},
},
},
},
},
}
rule := NewAwsSecurityGroupRuleInvalidProtocolRule()
for _, tc := range cases {
runner := helper.TestRunner(t, map[string]string{"resource.tf": tc.Content})
if err := rule.Check(runner); err != nil {
t.Fatalf("Unexpected error occurred: %s", err)
}
helper.AssertIssues(t, tc.Expected, runner.Issues)
}
}