Skip to content

Commit 64921fd

Browse files
committed
test: Add unit tests for zone-redundant load balancers
Add comprehensive unit tests for zone-redundant load balancer functionality: - Add test fixture (fakeInternalAPILBSpecWithZones) with zone configuration - Add test case to verify zones are correctly set on frontend IP configs - Validate that zones array contains all expected zone values (1, 2, 3) - Ensure zones are properly converted to Azure SDK format The tests verify that the service layer correctly translates the API spec into Azure SDK structures with zones on frontend IP configurations.
1 parent 8b04806 commit 64921fd

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

azure/services/loadbalancers/loadbalancers_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,30 @@ var (
111111
APIServerPort: 6443,
112112
}
113113

114+
fakeInternalAPILBSpecWithZones = LBSpec{
115+
Name: "my-private-lb",
116+
ResourceGroup: "my-rg",
117+
SubscriptionID: "123",
118+
ClusterName: "my-cluster",
119+
Location: "my-location",
120+
Role: infrav1.APIServerRole,
121+
Type: infrav1.Internal,
122+
SKU: infrav1.SKUStandard,
123+
SubnetName: "my-cp-subnet",
124+
BackendPoolName: "my-private-lb-backendPool",
125+
IdleTimeoutInMinutes: ptr.To[int32](4),
126+
AvailabilityZones: []string{"1", "2", "3"},
127+
FrontendIPConfigs: []infrav1.FrontendIP{
128+
{
129+
Name: "my-private-lb-frontEnd",
130+
FrontendIPClass: infrav1.FrontendIPClass{
131+
PrivateIPAddress: "10.0.0.10",
132+
},
133+
},
134+
},
135+
APIServerPort: 6443,
136+
}
137+
114138
fakeNodeOutboundLBSpec = LBSpec{
115139
Name: "my-cluster",
116140
ResourceGroup: "my-rg",

azure/services/loadbalancers/spec_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ func TestParameters(t *testing.T) {
178178
},
179179
expectedError: "",
180180
},
181+
{
182+
name: "internal load balancer with availability zones",
183+
spec: &fakeInternalAPILBSpecWithZones,
184+
existing: nil,
185+
expect: func(g *WithT, result interface{}) {
186+
g.Expect(result).To(BeAssignableToTypeOf(armnetwork.LoadBalancer{}))
187+
lb := result.(armnetwork.LoadBalancer)
188+
// Verify zones are set on frontend IP configuration
189+
g.Expect(lb.Properties.FrontendIPConfigurations).To(HaveLen(1))
190+
g.Expect(lb.Properties.FrontendIPConfigurations[0].Zones).To(HaveLen(3))
191+
g.Expect(*lb.Properties.FrontendIPConfigurations[0].Zones[0]).To(Equal("1"))
192+
g.Expect(*lb.Properties.FrontendIPConfigurations[0].Zones[1]).To(Equal("2"))
193+
g.Expect(*lb.Properties.FrontendIPConfigurations[0].Zones[2]).To(Equal("3"))
194+
},
195+
expectedError: "",
196+
},
181197
}
182198
for _, tc := range testcases {
183199
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)