-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig_test.go
147 lines (132 loc) · 2.38 KB
/
config_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package awses_test
import (
"reflect"
"testing"
"github.com/mholt/caddy"
"github.com/miquella/caddy-awses"
)
type TestCase struct {
Caddyfile string
Configs []awses.Config
}
var TestCases = map[string]TestCase{
"Basic": TestCase{
Caddyfile: `
awses
`,
Configs: []awses.Config{
{
Path: "",
},
},
},
"Prefix": TestCase{
Caddyfile: `
awses /with/prefix
`,
Configs: []awses.Config{
{
Path: "/with/prefix",
},
},
},
"Domain": TestCase{
Caddyfile: `
awses {
domain some-domain
}
`,
Configs: []awses.Config{
{
Domain: "some-domain",
},
},
},
"Region": TestCase{
Caddyfile: `
awses {
region ap-northeast-1
}
`,
Configs: []awses.Config{
{
Region: "ap-northeast-1",
},
},
},
"Role": TestCase{
Caddyfile: `
awses {
role arn:aws:iam::123456789012:role/some-role
}
`,
Configs: []awses.Config{
{
Role: "arn:aws:iam::123456789012:role/some-role",
},
},
},
"Full": TestCase{
Caddyfile: `
awses /a/prefix/ {
domain a-domain
region ap-southeast-2
role arn:aws:iam::123456789012:role/xacct
}
`,
Configs: []awses.Config{
{
Path: "/a/prefix",
Domain: "a-domain",
Region: "ap-southeast-2",
Role: "arn:aws:iam::123456789012:role/xacct",
},
},
},
"Multi": TestCase{
Caddyfile: `
awses /middle {
domain middle
}
awses /longest {
region us-east-1
}
awses /last {
role arn:aws:iam::123456789012:role/last
}
`,
Configs: []awses.Config{
{
Path: "/longest",
Region: "us-east-1",
},
{
Path: "/middle",
Domain: "middle",
},
{
Path: "/last",
Role: "arn:aws:iam::123456789012:role/last",
},
},
},
}
func TestParseConfigs(t *testing.T) {
for key, testCase := range TestCases {
controller := caddy.NewTestController("", testCase.Caddyfile)
configs, err := awses.ParseConfigs(controller)
if err != nil {
t.Errorf("Failed to parse '%s' Caddyfile: %v\n%s", key, err, testCase.Caddyfile)
continue
}
if len(configs) != len(testCase.Configs) {
t.Errorf("Wrong number of configs parsed: %d, expected %d", len(configs), len(testCase.Configs))
continue
}
for i := range testCase.Configs {
if !reflect.DeepEqual(*configs[i], testCase.Configs[i]) {
t.Errorf("Incorrect config:\n%#v\nexpected:\n%#v", *configs[i], testCase.Configs[i])
}
}
}
}