@@ -88,9 +88,15 @@ func Test_defaultSecurityGroupResolver_ResolveViaNameOrID(t *testing.T) {
88
88
resp : []* ec2sdk.SecurityGroup {
89
89
{
90
90
GroupId : awssdk .String ("sg-0912f63b" ),
91
+ Tags : []* ec2sdk.Tag {
92
+ {Key : awssdk .String ("Name" ), Value : awssdk .String ("sg group one" )},
93
+ },
91
94
},
92
95
{
93
96
GroupId : awssdk .String ("sg-08982de7" ),
97
+ Tags : []* ec2sdk.Tag {
98
+ {Key : awssdk .String ("Name" ), Value : awssdk .String ("sg group two" )},
99
+ },
94
100
},
95
101
},
96
102
},
@@ -101,6 +107,50 @@ func Test_defaultSecurityGroupResolver_ResolveViaNameOrID(t *testing.T) {
101
107
"sg-0912f63b" ,
102
108
},
103
109
},
110
+ {
111
+ name : "single name multiple ids" ,
112
+ args : args {
113
+ nameOrIDs : []string {
114
+ "sg group one" ,
115
+ },
116
+ describeSGCalls : []describeSecurityGroupsAsListCall {
117
+ {
118
+ req : & ec2sdk.DescribeSecurityGroupsInput {
119
+ Filters : []* ec2sdk.Filter {
120
+ {
121
+ Name : awssdk .String ("tag:Name" ),
122
+ Values : awssdk .StringSlice ([]string {
123
+ "sg group one" ,
124
+ }),
125
+ },
126
+ {
127
+ Name : awssdk .String ("vpc-id" ),
128
+ Values : awssdk .StringSlice ([]string {defaultVPCID }),
129
+ },
130
+ },
131
+ },
132
+ resp : []* ec2sdk.SecurityGroup {
133
+ {
134
+ GroupId : awssdk .String ("sg-id1" ),
135
+ Tags : []* ec2sdk.Tag {
136
+ {Key : awssdk .String ("Name" ), Value : awssdk .String ("sg group one" )},
137
+ },
138
+ },
139
+ {
140
+ GroupId : awssdk .String ("sg-id2" ),
141
+ Tags : []* ec2sdk.Tag {
142
+ {Key : awssdk .String ("Name" ), Value : awssdk .String ("sg group one" )},
143
+ },
144
+ },
145
+ },
146
+ },
147
+ },
148
+ },
149
+ want : []string {
150
+ "sg-id1" ,
151
+ "sg-id2" ,
152
+ },
153
+ },
104
154
{
105
155
name : "mixed group name and id" ,
106
156
args : args {
@@ -127,6 +177,9 @@ func Test_defaultSecurityGroupResolver_ResolveViaNameOrID(t *testing.T) {
127
177
resp : []* ec2sdk.SecurityGroup {
128
178
{
129
179
GroupId : awssdk .String ("sg-0912f63b" ),
180
+ Tags : []* ec2sdk.Tag {
181
+ {Key : awssdk .String ("Name" ), Value : awssdk .String ("sg group one" )},
182
+ },
130
183
},
131
184
},
132
185
},
@@ -151,7 +204,6 @@ func Test_defaultSecurityGroupResolver_ResolveViaNameOrID(t *testing.T) {
151
204
name : "describe by id returns error" ,
152
205
args : args {
153
206
nameOrIDs : []string {
154
- "sg group name" ,
155
207
"sg-id" ,
156
208
},
157
209
describeSGCalls : []describeSecurityGroupsAsListCall {
@@ -163,24 +215,21 @@ func Test_defaultSecurityGroupResolver_ResolveViaNameOrID(t *testing.T) {
163
215
},
164
216
},
165
217
},
166
- wantErr : errors .New ("Describe.Error: unable to describe security groups" ),
218
+ wantErr : errors .New ("couldn't find all security groups: Describe.Error: unable to describe security groups" ),
167
219
},
168
220
{
169
221
name : "describe by name returns error" ,
170
222
args : args {
171
223
nameOrIDs : []string {
172
224
"sg group name" ,
173
- "sg-id" ,
174
225
},
175
226
describeSGCalls : []describeSecurityGroupsAsListCall {
176
227
{
177
228
req : & ec2sdk.DescribeSecurityGroupsInput {
178
229
Filters : []* ec2sdk.Filter {
179
230
{
180
- Name : awssdk .String ("tag:Name" ),
181
- Values : awssdk .StringSlice ([]string {
182
- "sg group name" ,
183
- }),
231
+ Name : awssdk .String ("tag:Name" ),
232
+ Values : awssdk .StringSlice ([]string {"sg group name" }),
184
233
},
185
234
{
186
235
Name : awssdk .String ("vpc-id" ),
@@ -190,27 +239,38 @@ func Test_defaultSecurityGroupResolver_ResolveViaNameOrID(t *testing.T) {
190
239
},
191
240
err : awserr .New ("Describe.Error" , "unable to describe security groups" , nil ),
192
241
},
242
+ },
243
+ },
244
+ wantErr : errors .New ("couldn't find all security groups: Describe.Error: unable to describe security groups" ),
245
+ },
246
+ {
247
+ name : "unable to resolve security groups by id" ,
248
+ args : args {
249
+ nameOrIDs : []string {
250
+ "sg-id1" ,
251
+ "sg-id404" ,
252
+ },
253
+ describeSGCalls : []describeSecurityGroupsAsListCall {
193
254
{
194
255
req : & ec2sdk.DescribeSecurityGroupsInput {
195
- GroupIds : awssdk .StringSlice ([]string {"sg-id " }),
256
+ GroupIds : awssdk .StringSlice ([]string {"sg-id1" , "sg-id404 " }),
196
257
},
197
258
resp : []* ec2sdk.SecurityGroup {
198
259
{
199
- GroupId : awssdk .String ("sg-id " ),
260
+ GroupId : awssdk .String ("sg-id1 " ),
200
261
},
201
262
},
202
263
},
203
264
},
204
265
},
205
- wantErr : errors .New ("Describe.Error: unable to describe security groups" ),
266
+ wantErr : errors .New ("couldn't find all security groups: requested ids [sg-id1, sg-id404] but found [sg-id1] " ),
206
267
},
207
268
{
208
- name : "unable to resolve all security groups" ,
269
+ name : "unable to resolve security groups by name " ,
209
270
args : args {
210
271
nameOrIDs : []string {
211
272
"sg group one" ,
212
- "sg-id1" ,
213
- "sg-id404" ,
273
+ "sg group two" ,
214
274
},
215
275
describeSGCalls : []describeSecurityGroupsAsListCall {
216
276
{
@@ -220,6 +280,7 @@ func Test_defaultSecurityGroupResolver_ResolveViaNameOrID(t *testing.T) {
220
280
Name : awssdk .String ("tag:Name" ),
221
281
Values : awssdk .StringSlice ([]string {
222
282
"sg group one" ,
283
+ "sg group two" ,
223
284
}),
224
285
},
225
286
{
@@ -231,22 +292,48 @@ func Test_defaultSecurityGroupResolver_ResolveViaNameOrID(t *testing.T) {
231
292
resp : []* ec2sdk.SecurityGroup {
232
293
{
233
294
GroupId : awssdk .String ("sg-0912f63b" ),
295
+ Tags : []* ec2sdk.Tag {
296
+ {Key : awssdk .String ("Name" ), Value : awssdk .String ("sg group one" )},
297
+ },
234
298
},
235
299
},
236
300
},
301
+ },
302
+ },
303
+ wantErr : errors .New ("couldn't find all security groups: requested names [sg group one, sg group two] but found [sg group one]" ),
304
+ },
305
+ {
306
+ name : "unable to resolve all security groups by ids and names" ,
307
+ args : args {
308
+ nameOrIDs : []string {
309
+ "sg-08982de7" ,
310
+ "sg group one" ,
311
+ },
312
+ describeSGCalls : []describeSecurityGroupsAsListCall {
237
313
{
238
314
req : & ec2sdk.DescribeSecurityGroupsInput {
239
- GroupIds : awssdk .StringSlice ([]string {"sg-id1" , "sg-id404 " }),
315
+ GroupIds : awssdk .StringSlice ([]string {"sg-08982de7 " }),
240
316
},
241
- resp : []* ec2sdk.SecurityGroup {
242
- {
243
- GroupId : awssdk .String ("sg-id1" ),
317
+ resp : []* ec2sdk.SecurityGroup {},
318
+ },
319
+ {
320
+ req : & ec2sdk.DescribeSecurityGroupsInput {
321
+ Filters : []* ec2sdk.Filter {
322
+ {
323
+ Name : awssdk .String ("tag:Name" ),
324
+ Values : awssdk .StringSlice ([]string {"sg group one" }),
325
+ },
326
+ {
327
+ Name : awssdk .String ("vpc-id" ),
328
+ Values : awssdk .StringSlice ([]string {defaultVPCID }),
329
+ },
244
330
},
245
331
},
332
+ resp : []* ec2sdk.SecurityGroup {},
246
333
},
247
334
},
248
335
},
249
- wantErr : errors .New ("couldn't find all securityGroups, nameOrIDs: [sg group one sg-id1 sg-id404 ], found: [sg-id1 sg-0912f63b ]" ),
336
+ wantErr : errors .New ("couldn't find all security groups: requested ids [ sg-08982de7] but found [ ], requested names [sg group one] but found [ ]" ),
250
337
},
251
338
}
252
339
0 commit comments