@@ -19,6 +19,7 @@ limitations under the License.
19
19
package azure
20
20
21
21
import (
22
+ "strconv"
22
23
"testing"
23
24
24
25
"github.com/stretchr/testify/assert"
@@ -253,3 +254,156 @@ func TestGetAzureLoadBalancerName(t *testing.T) {
253
254
assert .Equal (t , c .expected , loadbalancerName , c .description )
254
255
}
255
256
}
257
+
258
+ func TestGetLoadBalancingRuleName (t * testing.T ) {
259
+ az := getTestCloud ()
260
+ az .PrimaryAvailabilitySetName = "primary"
261
+
262
+ svc := & v1.Service {
263
+ ObjectMeta : meta.ObjectMeta {
264
+ Annotations : map [string ]string {},
265
+ UID : "257b9655-5137-4ad2-b091-ef3f07043ad3" ,
266
+ },
267
+ }
268
+
269
+ cases := []struct {
270
+ description string
271
+ subnetName string
272
+ isInternal bool
273
+ useStandardLB bool
274
+ protocol v1.Protocol
275
+ port int32
276
+ expected string
277
+ }{
278
+ {
279
+ description : "internal lb should have subnet name on the rule name" ,
280
+ subnetName : "shortsubnet" ,
281
+ isInternal : true ,
282
+ useStandardLB : true ,
283
+ protocol : v1 .ProtocolTCP ,
284
+ port : 9000 ,
285
+ expected : "a257b965551374ad2b091ef3f07043ad-shortsubnet-TCP-9000" ,
286
+ },
287
+ {
288
+ description : "internal standard lb should have subnet name on the rule name but truncated to 80 characters" ,
289
+ subnetName : "averylonnnngggnnnnnnnnnnnnnnnnnnnnnngggggggggggggggggggggggggggggggggggggsubet" ,
290
+ isInternal : true ,
291
+ useStandardLB : true ,
292
+ protocol : v1 .ProtocolTCP ,
293
+ port : 9000 ,
294
+ expected : "a257b965551374ad2b091ef3f07043ad-averylonnnngggnnnnnnnnnnnnnnnnnnnnnngg-TCP-9000" ,
295
+ },
296
+ {
297
+ description : "internal basic lb should have subnet name on the rule name but truncated to 80 characters" ,
298
+ subnetName : "averylonnnngggnnnnnnnnnnnnnnnnnnnnnngggggggggggggggggggggggggggggggggggggsubet" ,
299
+ isInternal : true ,
300
+ useStandardLB : false ,
301
+ protocol : v1 .ProtocolTCP ,
302
+ port : 9000 ,
303
+ expected : "a257b965551374ad2b091ef3f07043ad-averylonnnngggnnnnnnnnnnnnnnnnnnnnnngg-TCP-9000" ,
304
+ },
305
+ {
306
+ description : "external standard lb should not have subnet name on the rule name" ,
307
+ subnetName : "shortsubnet" ,
308
+ isInternal : false ,
309
+ useStandardLB : true ,
310
+ protocol : v1 .ProtocolTCP ,
311
+ port : 9000 ,
312
+ expected : "a257b965551374ad2b091ef3f07043ad-TCP-9000" ,
313
+ },
314
+ {
315
+ description : "external basic lb should not have subnet name on the rule name" ,
316
+ subnetName : "shortsubnet" ,
317
+ isInternal : false ,
318
+ useStandardLB : false ,
319
+ protocol : v1 .ProtocolTCP ,
320
+ port : 9000 ,
321
+ expected : "a257b965551374ad2b091ef3f07043ad-TCP-9000" ,
322
+ },
323
+ }
324
+
325
+ for _ , c := range cases {
326
+ if c .useStandardLB {
327
+ az .Config .LoadBalancerSku = loadBalancerSkuStandard
328
+ } else {
329
+ az .Config .LoadBalancerSku = loadBalancerSkuBasic
330
+ }
331
+ svc .Annotations [ServiceAnnotationLoadBalancerInternalSubnet ] = c .subnetName
332
+ svc .Annotations [ServiceAnnotationLoadBalancerInternal ] = strconv .FormatBool (c .isInternal )
333
+
334
+ loadbalancerRuleName := az .getLoadBalancerRuleName (svc , c .protocol , c .port )
335
+ assert .Equal (t , c .expected , loadbalancerRuleName , c .description )
336
+ }
337
+ }
338
+
339
+ func TestGetFrontendIPConfigName (t * testing.T ) {
340
+ az := getTestCloud ()
341
+ az .PrimaryAvailabilitySetName = "primary"
342
+
343
+ svc := & v1.Service {
344
+ ObjectMeta : meta.ObjectMeta {
345
+ Annotations : map [string ]string {
346
+ ServiceAnnotationLoadBalancerInternalSubnet : "subnet" ,
347
+ ServiceAnnotationLoadBalancerInternal : "true" ,
348
+ },
349
+ UID : "257b9655-5137-4ad2-b091-ef3f07043ad3" ,
350
+ },
351
+ }
352
+
353
+ cases := []struct {
354
+ description string
355
+ subnetName string
356
+ isInternal bool
357
+ useStandardLB bool
358
+ expected string
359
+ }{
360
+ {
361
+ description : "internal lb should have subnet name on the frontend ip configuration name" ,
362
+ subnetName : "shortsubnet" ,
363
+ isInternal : true ,
364
+ useStandardLB : true ,
365
+ expected : "a257b965551374ad2b091ef3f07043ad-shortsubnet" ,
366
+ },
367
+ {
368
+ description : "internal standard lb should have subnet name on the frontend ip configuration name but truncated to 80 characters" ,
369
+ subnetName : "averylonnnngggnnnnnnnnnnnnnnnnnnnnnngggggggggggggggggggggggggggggggggggggsubet" ,
370
+ isInternal : true ,
371
+ useStandardLB : true ,
372
+ expected : "a257b965551374ad2b091ef3f07043ad-averylonnnngggnnnnnnnnnnnnnnnnnnnnnnggggggggggg" ,
373
+ },
374
+ {
375
+ description : "internal basic lb should have subnet name on the frontend ip configuration name but truncated to 80 characters" ,
376
+ subnetName : "averylonnnngggnnnnnnnnnnnnnnnnnnnnnngggggggggggggggggggggggggggggggggggggsubet" ,
377
+ isInternal : true ,
378
+ useStandardLB : false ,
379
+ expected : "a257b965551374ad2b091ef3f07043ad-averylonnnngggnnnnnnnnnnnnnnnnnnnnnnggggggggggg" ,
380
+ },
381
+ {
382
+ description : "external standard lb should not have subnet name on the frontend ip configuration name" ,
383
+ subnetName : "shortsubnet" ,
384
+ isInternal : false ,
385
+ useStandardLB : true ,
386
+ expected : "a257b965551374ad2b091ef3f07043ad" ,
387
+ },
388
+ {
389
+ description : "external basic lb should not have subnet name on the frontend ip configuration name" ,
390
+ subnetName : "shortsubnet" ,
391
+ isInternal : false ,
392
+ useStandardLB : false ,
393
+ expected : "a257b965551374ad2b091ef3f07043ad" ,
394
+ },
395
+ }
396
+
397
+ for _ , c := range cases {
398
+ if c .useStandardLB {
399
+ az .Config .LoadBalancerSku = loadBalancerSkuStandard
400
+ } else {
401
+ az .Config .LoadBalancerSku = loadBalancerSkuBasic
402
+ }
403
+ svc .Annotations [ServiceAnnotationLoadBalancerInternalSubnet ] = c .subnetName
404
+ svc .Annotations [ServiceAnnotationLoadBalancerInternal ] = strconv .FormatBool (c .isInternal )
405
+
406
+ ipconfigName := az .getFrontendIPConfigName (svc )
407
+ assert .Equal (t , c .expected , ipconfigName , c .description )
408
+ }
409
+ }
0 commit comments