Skip to content

Commit ac1b07f

Browse files
committed
add test
1 parent 1f8633d commit ac1b07f

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

pkg/provider/azure_loadbalancer_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8517,6 +8517,93 @@ func TestServiceOwnsFrontendIP(t *testing.T) {
85178517
}
85188518
}
85198519

8520+
func TestFindFrontendIPConfigsOfService(t *testing.T) {
8521+
ctrl := gomock.NewController(t)
8522+
defer ctrl.Finish()
8523+
8524+
testCases := []struct {
8525+
desc string
8526+
existingPIPs []*armnetwork.PublicIPAddress
8527+
fip *armnetwork.FrontendIPConfiguration
8528+
service *v1.Service
8529+
isIPv6 bool
8530+
}{
8531+
{
8532+
desc: "config works for ipv6 service",
8533+
existingPIPs: []*armnetwork.PublicIPAddress{
8534+
{
8535+
Name: ptr.To("pip1"),
8536+
ID: ptr.To("pip1"),
8537+
Properties: &armnetwork.PublicIPAddressPropertiesFormat{
8538+
IPAddress: ptr.To("fd00::eef0"),
8539+
PublicIPAddressVersion: to.Ptr(armnetwork.IPVersionIPv6),
8540+
},
8541+
},
8542+
},
8543+
fip: &armnetwork.FrontendIPConfiguration{
8544+
Name: ptr.To("auid"),
8545+
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
8546+
PublicIPAddress: &armnetwork.PublicIPAddress{
8547+
ID: ptr.To("pip1"),
8548+
},
8549+
},
8550+
},
8551+
service: &v1.Service{
8552+
ObjectMeta: metav1.ObjectMeta{
8553+
UID: types.UID("secondary"),
8554+
Annotations: map[string]string{consts.ServiceAnnotationPIPNameDualStack[false]: "pip1"},
8555+
},
8556+
},
8557+
isIPv6: true,
8558+
},
8559+
{
8560+
desc: "config works for ipv4 service",
8561+
existingPIPs: []*armnetwork.PublicIPAddress{
8562+
{
8563+
Name: ptr.To("pip1"),
8564+
ID: ptr.To("pip1"),
8565+
Properties: &armnetwork.PublicIPAddressPropertiesFormat{
8566+
IPAddress: ptr.To("4.3.2.1"),
8567+
PublicIPAddressVersion: to.Ptr(armnetwork.IPVersionIPv4),
8568+
},
8569+
},
8570+
},
8571+
fip: &armnetwork.FrontendIPConfiguration{
8572+
Name: ptr.To("auid"),
8573+
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
8574+
PublicIPAddress: &armnetwork.PublicIPAddress{
8575+
ID: ptr.To("pip1"),
8576+
},
8577+
},
8578+
},
8579+
service: &v1.Service{
8580+
ObjectMeta: metav1.ObjectMeta{
8581+
UID: types.UID("secondary"),
8582+
Annotations: map[string]string{consts.ServiceAnnotationPIPNameDualStack[false]: "pip1"},
8583+
},
8584+
},
8585+
},
8586+
}
8587+
8588+
for _, test := range testCases {
8589+
test := test
8590+
t.Run(test.desc, func(t *testing.T) {
8591+
cloud := GetTestCloud(ctrl)
8592+
if test.existingPIPs != nil {
8593+
mockPIPsClient := cloud.NetworkClientFactory.GetPublicIPAddressClient().(*mock_publicipaddressclient.MockInterface)
8594+
mockPIPsClient.EXPECT().List(gomock.Any(), "rg").Return(test.existingPIPs, nil).MaxTimes(2)
8595+
}
8596+
configs, err := cloud.findFrontendIPConfigsOfService(context.TODO(), []*armnetwork.FrontendIPConfiguration{test.fip}, test.service)
8597+
if err != nil {
8598+
t.Fatalf("unexpected error: %v", err)
8599+
}
8600+
assert.Equal(t, 1, len(configs))
8601+
assert.NotNil(t, configs[test.isIPv6])
8602+
assert.Equal(t, test.fip, configs[test.isIPv6])
8603+
})
8604+
}
8605+
}
8606+
85208607
func TestReconcileMultipleStandardLoadBalancerNodes(t *testing.T) {
85218608
ctrl := gomock.NewController(t)
85228609
defer ctrl.Finish()

0 commit comments

Comments
 (0)