Skip to content

Commit

Permalink
add nil check to RemoveFrontendIPConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-schndr committed Dec 5, 2023
1 parent e777309 commit 7800f4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/util/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
)

func RemoveFrontendIPConfiguration(lb *mgmtnetwork.LoadBalancer, resourceID string) error {
if lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations == nil {
return fmt.Errorf("FrontendIPConfigurations in nil!")

Check failure on line 19 in pkg/util/loadbalancer/loadbalancer.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ST1005: error strings should not end with punctuation or newlines (stylecheck)
}

newFrontendIPConfig := make([]mgmtnetwork.FrontendIPConfiguration, 0, len(*lb.FrontendIPConfigurations))
for _, fipConfig := range *lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations {
if strings.EqualFold(*fipConfig.ID, resourceID) {
Expand Down
11 changes: 11 additions & 0 deletions pkg/util/loadbalancer/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ func TestRemoveLoadBalancerFrontendIPConfiguration(t *testing.T) {
expectedLB: originalLB,
expectedErr: fmt.Sprintf("frontend IP Configuration %s has external references, remove the external references prior to removing the frontend IP configuration", *publicIngressFIPConfigID),
},
{
name: "removal of frontend ip config fails when frontend ip config doesn't exist",
fipResourceID: *publicIngressFIPConfigID,
currentLB: mgmtnetwork.LoadBalancer{
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{},
},
expectedLB: mgmtnetwork.LoadBalancer{
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{},
},
expectedErr: fmt.Sprintf("FrontendIPConfigurations in nil!"),

Check failure on line 137 in pkg/util/loadbalancer/loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
},
} {
t.Run(tt.name, func(t *testing.T) {
err := RemoveFrontendIPConfiguration(&tt.currentLB, tt.fipResourceID)
Expand Down

0 comments on commit 7800f4d

Please sign in to comment.