@@ -24,10 +24,10 @@ import (
24
24
v1 "k8s.io/api/core/v1"
25
25
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
26
27
+ providercfg "github.com/oracle/oci-cloud-controller-manager/pkg/cloudprovider/providers/oci/config"
28
+ "github.com/oracle/oci-cloud-controller-manager/pkg/oci/client"
27
29
"github.com/oracle/oci-go-sdk/v50/common"
28
30
"github.com/oracle/oci-go-sdk/v50/core"
29
- "github.com/oracle/oci-cloud-controller-manager/pkg/oci/client"
30
- providercfg "github.com/oracle/oci-cloud-controller-manager/pkg/cloudprovider/providers/oci/config"
31
31
)
32
32
33
33
func Test_getDefaultLBSubnets (t * testing.T ) {
@@ -476,7 +476,7 @@ func TestUpdateLoadBalancerNetworkSecurityGroups(t *testing.T) {
476
476
loadbalancer * client.GenericLoadBalancer
477
477
wantErr error
478
478
}{
479
- "Update NSG when there's an issue with LB " : {
479
+ "lb id is missing " : {
480
480
spec : & LBSpec {
481
481
Name : "test" ,
482
482
NetworkSecurityGroupIds : []string {"ocid1" },
@@ -485,7 +485,29 @@ func TestUpdateLoadBalancerNetworkSecurityGroups(t *testing.T) {
485
485
Id : common .String ("" ),
486
486
DisplayName : common .String ("privateLB" ),
487
487
},
488
- wantErr : errors .New ("failed to update loadbalancer Network Security Group: provided LB ID is empty" ),
488
+ wantErr : errors .New ("failed to create UpdateNetworkSecurityGroups request: provided LB ID is empty" ),
489
+ },
490
+ "failed to create workrequest" : {
491
+ spec : & LBSpec {
492
+ Name : "test" ,
493
+ NetworkSecurityGroupIds : []string {"ocid1" },
494
+ },
495
+ loadbalancer : & client.GenericLoadBalancer {
496
+ Id : common .String ("failedToCreateRequest" ),
497
+ DisplayName : common .String ("privateLB" ),
498
+ },
499
+ wantErr : errors .New ("failed to create UpdateNetworkSecurityGroups request: internal server error" ),
500
+ },
501
+ "failed to get workrequest" : {
502
+ spec : & LBSpec {
503
+ Name : "test" ,
504
+ NetworkSecurityGroupIds : []string {"ocid1" },
505
+ },
506
+ loadbalancer : & client.GenericLoadBalancer {
507
+ Id : common .String ("failedToGetUpdateNetworkSecurityGroupsWorkRequest" ),
508
+ DisplayName : common .String ("privateLB" ),
509
+ },
510
+ wantErr : errors .New ("failed to await UpdateNetworkSecurityGroups workrequest: internal server error for get workrequest call" ),
489
511
},
490
512
"Update NSG to existing LB" : {
491
513
spec : & LBSpec {
@@ -507,8 +529,8 @@ func TestUpdateLoadBalancerNetworkSecurityGroups(t *testing.T) {
507
529
for name , tt := range tests {
508
530
t .Run (name , func (t * testing.T ) {
509
531
err := cp .updateLoadBalancerNetworkSecurityGroups (context .Background (), tt .loadbalancer , tt .spec )
510
- if err != nil && err . Error () != tt .wantErr . Error ( ) {
511
- t .Errorf ("Expected error = %v, but got %v" , err , tt .wantErr )
532
+ if ! assertError ( err , tt .wantErr ) {
533
+ t .Errorf ("Expected error = %v, but got %v" , tt .wantErr , err )
512
534
return
513
535
}
514
536
})
@@ -626,3 +648,10 @@ func TestCloudProvider_EnsureLoadBalancerDeleted(t *testing.T) {
626
648
})
627
649
}
628
650
}
651
+
652
+ func assertError (actual , expected error ) bool {
653
+ if expected == nil || actual == nil {
654
+ return expected == actual
655
+ }
656
+ return actual .Error () == expected .Error ()
657
+ }
0 commit comments