Skip to content

Commit

Permalink
test: LbaasV2 method buildPoolCreateOpt
Browse files Browse the repository at this point in the history
  • Loading branch information
majorchork committed Oct 9, 2023
1 parent 5e2668a commit a053a84
Showing 1 changed file with 193 additions and 0 deletions.
193 changes: 193 additions & 0 deletions pkg/openstack/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners"
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -534,3 +535,195 @@ func Test_getListenerProtocol(t *testing.T) {
})
}
}

func Test_buildPoolCreateOpt(t *testing.T) {
type args struct {
protocol string
svcConf *serviceConfig
service *corev1.Service
lbaasV2 *LbaasV2
}
tests := []struct {
name string
args args
want pools.CreateOpts
}{
{
name: "test for proxy protocol enabled",
args: args{
protocol: "TCP",
svcConf: &serviceConfig{
keepClientIP: true,
tlsContainerRef: "tls-container-ref",
healthMonitorDelay: 1,
healthMonitorTimeout: 1,
healthMonitorMaxRetries: 1,
healthMonitorMaxRetriesDown: 1,
healthCheckNodePort: 2,
enableProxyProtocol: true,
},
lbaasV2: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "ovn",
LBMethod: "ROUND_ROBIN",
},
},
},
service: &corev1.Service{
Spec: corev1.ServiceSpec{
SessionAffinity: corev1.ServiceAffinityClientIP,
},
},
},
want: pools.CreateOpts{
Protocol: pools.ProtocolPROXY,
LBMethod: "ROUND_ROBIN",
Persistence: &pools.SessionPersistence{Type: "SOURCE_IP"},
},
},
{
name: "test for pool protocol http with proxy protocol disabled",
args: args{
protocol: "HTTP",
svcConf: &serviceConfig{
keepClientIP: true,
tlsContainerRef: "tls-container-ref",
healthMonitorDelay: 1,
healthMonitorTimeout: 1,
healthMonitorMaxRetries: 1,
healthMonitorMaxRetriesDown: 1,
healthCheckNodePort: 2,
enableProxyProtocol: false,
},
lbaasV2: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "ovn",
LBMethod: "ROUND_ROBIN",
},
},
},
service: &corev1.Service{
Spec: corev1.ServiceSpec{
SessionAffinity: corev1.ServiceAffinityClientIP,
},
},
},
want: pools.CreateOpts{
Protocol: pools.ProtocolHTTP,
LBMethod: "ROUND_ROBIN",
Persistence: &pools.SessionPersistence{Type: "SOURCE_IP"},
},
},
{
name: "test for pool protocol UDP with proxy protocol disabled",
args: args{
protocol: "UDP",
svcConf: &serviceConfig{
keepClientIP: true,
tlsContainerRef: "tls-container-ref",
healthMonitorDelay: 1,
healthMonitorTimeout: 1,
healthMonitorMaxRetries: 1,
healthMonitorMaxRetriesDown: 1,
healthCheckNodePort: 2,
enableProxyProtocol: false,
},
lbaasV2: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "ovn",
LBMethod: "ROUND_ROBIN",
},
},
},
service: &corev1.Service{
Spec: corev1.ServiceSpec{
SessionAffinity: corev1.ServiceAffinityClientIP,
},
},
},
want: pools.CreateOpts{
Protocol: pools.ProtocolHTTP,
LBMethod: "ROUND_ROBIN",
Persistence: &pools.SessionPersistence{Type: "SOURCE_IP"},
},
},
{
name: "test for session affinity none",
args: args{
protocol: "TCP",
svcConf: &serviceConfig{
keepClientIP: true,
tlsContainerRef: "tls-container-ref",
healthMonitorDelay: 1,
healthMonitorTimeout: 1,
healthMonitorMaxRetries: 1,
healthMonitorMaxRetriesDown: 1,
healthCheckNodePort: 2,
},
lbaasV2: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "ovn",
LBMethod: "ROUND_ROBIN",
},
},
},
service: &corev1.Service{
Spec: corev1.ServiceSpec{
SessionAffinity: corev1.ServiceAffinityNone,
},
},
},
want: pools.CreateOpts{
Protocol: pools.ProtocolHTTP,
LBMethod: "ROUND_ROBIN",
Persistence: nil,
},
},
{
name: "test for session affinity client ip",
args: args{
protocol: "TCP",
svcConf: &serviceConfig{
keepClientIP: true,
tlsContainerRef: "tls-container-ref",
healthMonitorDelay: 1,
healthMonitorTimeout: 1,
healthMonitorMaxRetries: 1,
healthMonitorMaxRetriesDown: 1,
healthCheckNodePort: 2,
},
lbaasV2: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "ovn",
LBMethod: "ROUND_ROBIN",
},
},
},
service: &corev1.Service{
Spec: corev1.ServiceSpec{
SessionAffinity: corev1.ServiceAffinityClientIP,
},
},
},
want: pools.CreateOpts{
Protocol: pools.ProtocolHTTP,
LBMethod: "ROUND_ROBIN",
Persistence: &pools.SessionPersistence{Type: "SOURCE_IP"},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.args.lbaasV2.buildPoolCreateOpt(tt.args.protocol, tt.args.service, tt.args.svcConf)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("buildPoolCreateOpt() = %v, expected %v", got, tt.want)
}
})
}
}

0 comments on commit a053a84

Please sign in to comment.