diff --git a/pkg/openstack/loadbalancer_test.go b/pkg/openstack/loadbalancer_test.go index 0cd33a7e2b..30d1ba171a 100644 --- a/pkg/openstack/loadbalancer_test.go +++ b/pkg/openstack/loadbalancer_test.go @@ -542,6 +542,10 @@ func TestLbaasV2_createLoadBalancerStatus(t *testing.T) { type fields struct { LoadBalancer LoadBalancer } + type result struct { + HostName *string + IPAddress *string + } type args struct { service *corev1.Service svcConf *serviceConfig @@ -551,7 +555,7 @@ func TestLbaasV2_createLoadBalancerStatus(t *testing.T) { name string fields fields args args - want *corev1.LoadBalancerStatus + want result }{ { name: "it should return hostname from service annotation", @@ -574,16 +578,12 @@ func TestLbaasV2_createLoadBalancerStatus(t *testing.T) { }, addr: "10.10.0.6", }, - want: &corev1.LoadBalancerStatus{ - Ingress: []corev1.LoadBalancerIngress{ - { - Hostname: "testHostName", - }, - }, + want: result{ + HostName: getStringPointer("testHostName"), }, }, { - name: "it should return fakehostname if proxyProtocal & IngressHostName is enabled without svc annotation", + name: "it should return fakehostname if proxyProtocol & IngressHostName is enabled without svc annotation", fields: fields{ LoadBalancer: LoadBalancer{ opts: LoadBalancerOpts{ @@ -603,12 +603,8 @@ func TestLbaasV2_createLoadBalancerStatus(t *testing.T) { }, addr: "10.10.0.6", }, - want: &corev1.LoadBalancerStatus{ - Ingress: []corev1.LoadBalancerIngress{ - { - Hostname: "10.10.0.6.ingress-suffix", - }, - }, + want: result{ + HostName: getStringPointer("10.10.0.6.ingress-suffix"), }, }, { @@ -632,12 +628,8 @@ func TestLbaasV2_createLoadBalancerStatus(t *testing.T) { }, addr: "10.10.0.6", }, - want: &corev1.LoadBalancerStatus{ - Ingress: []corev1.LoadBalancerIngress{ - { - IP: "10.10.0.6", - }, - }, + want: result{ + IPAddress: getStringPointer("10.10.0.6"), }, }, } @@ -646,7 +638,12 @@ func TestLbaasV2_createLoadBalancerStatus(t *testing.T) { lbaas := &LbaasV2{ LoadBalancer: tt.fields.LoadBalancer, } - assert.Equal(t, tt.want, lbaas.createLoadBalancerStatus(tt.args.service, tt.args.svcConf, tt.args.addr)) + if tt.want.HostName != nil { + assert.Equal(t, *tt.want.HostName, lbaas.createLoadBalancerStatus(tt.args.service, tt.args.svcConf, tt.args.addr).Ingress[0].Hostname) + } + if tt.want.IPAddress != nil { + assert.Equal(t, *tt.want.IPAddress, lbaas.createLoadBalancerStatus(tt.args.service, tt.args.svcConf, tt.args.addr).Ingress[0].IP) + } }) } } @@ -937,6 +934,7 @@ func Test_buildPoolCreateOpt(t *testing.T) { }) } } + func Test_getSecurityGroupName(t *testing.T) { tests := []struct { name string @@ -1085,3 +1083,7 @@ func TestLbaasV2_updateServiceAnnotations(t *testing.T) { assert.ElementsMatch(t, expectedAnnotations, serviceAnnotations) } + +func getStringPointer(v string) *string { + return &v +}