@@ -19,6 +19,7 @@ limitations under the License.
19
19
package azure
20
20
21
21
import (
22
+ "fmt"
22
23
"strconv"
23
24
"testing"
24
25
@@ -29,6 +30,11 @@ import (
29
30
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
30
31
)
31
32
33
+ const (
34
+ networkResourceTenantID = "networkResourceTenantID"
35
+ networkResourceSubscriptionID = "networkResourceSubscriptionID"
36
+ )
37
+
32
38
func TestIsMasterNode (t * testing.T ) {
33
39
if isMasterNode (& v1.Node {}) {
34
40
t .Errorf ("Empty node should not be master!" )
@@ -416,3 +422,81 @@ func TestGetFrontendIPConfigName(t *testing.T) {
416
422
assert .Equal (t , c .expected , ipconfigName , c .description )
417
423
}
418
424
}
425
+
426
+ func TestGetFrontendIPConfigID (t * testing.T ) {
427
+ ctrl := gomock .NewController (t )
428
+ defer ctrl .Finish ()
429
+ az := GetTestCloud (ctrl )
430
+
431
+ testGetLoadBalancerSubResourceID (t , az , az .getFrontendIPConfigID , frontendIPConfigIDTemplate )
432
+ }
433
+
434
+ func TestGetBackendPoolID (t * testing.T ) {
435
+ ctrl := gomock .NewController (t )
436
+ defer ctrl .Finish ()
437
+ az := GetTestCloud (ctrl )
438
+
439
+ testGetLoadBalancerSubResourceID (t , az , az .getBackendPoolID , backendPoolIDTemplate )
440
+ }
441
+
442
+ func TestGetLoadBalancerProbeID (t * testing.T ) {
443
+ ctrl := gomock .NewController (t )
444
+ defer ctrl .Finish ()
445
+ az := GetTestCloud (ctrl )
446
+
447
+ testGetLoadBalancerSubResourceID (t , az , az .getLoadBalancerProbeID , loadBalancerProbeIDTemplate )
448
+ }
449
+
450
+ func testGetLoadBalancerSubResourceID (
451
+ t * testing.T ,
452
+ az * Cloud ,
453
+ getLoadBalancerSubResourceID func (string , string , string ) string ,
454
+ expectedResourceIDTemplate string ) {
455
+ cases := []struct {
456
+ description string
457
+ loadBalancerName string
458
+ resourceGroupName string
459
+ subResourceName string
460
+ useNetworkResourceInDifferentTenant bool
461
+ expected string
462
+ }{
463
+ {
464
+ description : "resource id should contain NetworkResourceSubscriptionID when using network resources in different subscription" ,
465
+ loadBalancerName : "lbName" ,
466
+ resourceGroupName : "rgName" ,
467
+ subResourceName : "subResourceName" ,
468
+ useNetworkResourceInDifferentTenant : true ,
469
+ },
470
+ {
471
+ description : "resource id should contain SubscriptionID when not using network resources in different subscription" ,
472
+ loadBalancerName : "lbName" ,
473
+ resourceGroupName : "rgName" ,
474
+ subResourceName : "subResourceName" ,
475
+ useNetworkResourceInDifferentTenant : false ,
476
+ },
477
+ }
478
+
479
+ for _ , c := range cases {
480
+ if c .useNetworkResourceInDifferentTenant {
481
+ az .NetworkResourceTenantID = networkResourceTenantID
482
+ az .NetworkResourceSubscriptionID = networkResourceSubscriptionID
483
+ c .expected = fmt .Sprintf (
484
+ expectedResourceIDTemplate ,
485
+ az .NetworkResourceSubscriptionID ,
486
+ c .resourceGroupName ,
487
+ c .loadBalancerName ,
488
+ c .subResourceName )
489
+ } else {
490
+ az .NetworkResourceTenantID = ""
491
+ az .NetworkResourceSubscriptionID = ""
492
+ c .expected = fmt .Sprintf (
493
+ expectedResourceIDTemplate ,
494
+ az .SubscriptionID ,
495
+ c .resourceGroupName ,
496
+ c .loadBalancerName ,
497
+ c .subResourceName )
498
+ }
499
+ subResourceID := getLoadBalancerSubResourceID (c .loadBalancerName , c .resourceGroupName , c .subResourceName )
500
+ assert .Equal (t , c .expected , subResourceID , c .description )
501
+ }
502
+ }
0 commit comments