forked from hashicorp/aws-sdk-go-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation_test.go
103 lines (96 loc) · 2.54 KB
/
validation_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package awsbase
import (
"testing"
)
func TestValidateAccountID(t *testing.T) {
var testCases = []struct {
Description string
AccountID string
AllowedAccountIDs []string
ForbiddenAccountIDs []string
ExpectError bool
}{
{
Description: "Allowed if no allowed or forbidden account IDs",
AccountID: "123456789012",
AllowedAccountIDs: []string{},
ForbiddenAccountIDs: []string{},
ExpectError: false,
},
{
Description: "Allowed if matches an allowed account ID",
AccountID: "123456789012",
AllowedAccountIDs: []string{"123456789012"},
ForbiddenAccountIDs: []string{},
ExpectError: false,
},
{
Description: "Allowed if does not match a forbidden account ID",
AccountID: "123456789012",
AllowedAccountIDs: []string{},
ForbiddenAccountIDs: []string{"111111111111"},
ExpectError: false,
},
{
Description: "Denied if matches a forbidden account ID",
AccountID: "123456789012",
AllowedAccountIDs: []string{},
ForbiddenAccountIDs: []string{"123456789012"},
ExpectError: true,
},
{
Description: "Denied if does not match an allowed account ID",
AccountID: "123456789012",
AllowedAccountIDs: []string{"111111111111"},
ForbiddenAccountIDs: []string{},
ExpectError: true,
},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.Description, func(t *testing.T) {
err := ValidateAccountID(testCase.AccountID, testCase.AllowedAccountIDs, testCase.ForbiddenAccountIDs)
if err != nil && !testCase.ExpectError {
t.Fatalf("Expected no error, received error: %s", err)
}
if err == nil && testCase.ExpectError {
t.Fatal("Expected error, received none")
}
})
}
}
func TestValidateRegion(t *testing.T) {
var testCases = []struct {
Region string
ExpectError bool
}{
{
Region: "us-east-1",
ExpectError: false,
},
{
Region: "us-gov-west-1",
ExpectError: false,
},
{
Region: "cn-northwest-1",
ExpectError: false,
},
{
Region: "invalid",
ExpectError: true,
},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.Region, func(t *testing.T) {
err := ValidateRegion(testCase.Region)
if err != nil && !testCase.ExpectError {
t.Fatalf("Expected no error, received error: %s", err)
}
if err == nil && testCase.ExpectError {
t.Fatal("Expected error, received none")
}
})
}
}