Skip to content

Commit

Permalink
test: LbaasV2 method buildMonitorCreateOpts (#2429)
Browse files Browse the repository at this point in the history
test: LbaasV2 method buildMonitorCreateOpts
  • Loading branch information
majorchork authored Oct 30, 2023
1 parent 1379d0f commit b1d415f
Showing 1 changed file with 149 additions and 0 deletions.
149 changes: 149 additions & 0 deletions pkg/openstack/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"sort"
"testing"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners"
v2monitors "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors"
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -2139,3 +2141,150 @@ func TestLbaasV2_getNetworkID(t *testing.T) {
})
}
}

func Test_buildMonitorCreateOpts(t *testing.T) {
type testArg struct {
lbaas *LbaasV2
svcConf *serviceConfig
port corev1.ServicePort
}
tests := []struct {
name string
testArg testArg
want v2monitors.CreateOpts
}{
{
name: "test for port protocol udp with ovn provider",
testArg: testArg{
lbaas: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "ovn",
},
lb: &gophercloud.ServiceClient{},
},
},
svcConf: &serviceConfig{
healthMonitorDelay: 6,
healthMonitorTimeout: 5,
healthMonitorMaxRetries: 4,
healthMonitorMaxRetriesDown: 3,
healthCheckNodePort: 32100,
},
port: corev1.ServicePort{
Protocol: corev1.ProtocolUDP,
},
},
want: v2monitors.CreateOpts{
Name: "test for port protocol udp with ovn provider",
Type: "UDP-CONNECT",
Delay: 6,
Timeout: 5,
MaxRetries: 4,
MaxRetriesDown: 3,
},
},
{
name: "using tcp with ovn provider",
testArg: testArg{
lbaas: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "ovn",
},
},
},
svcConf: &serviceConfig{
healthMonitorDelay: 3,
healthMonitorTimeout: 8,
healthMonitorMaxRetries: 6,
healthMonitorMaxRetriesDown: 2,
healthCheckNodePort: 31200,
},
port: corev1.ServicePort{
Protocol: corev1.ProtocolTCP,
},
},
want: v2monitors.CreateOpts{
Name: "using tcp with ovn provider",
Type: "TCP",
Delay: 3,
Timeout: 8,
MaxRetries: 6,
MaxRetriesDown: 2,
},
},
{
name: "using node port zero",
testArg: testArg{
lbaas: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "ovn",
},
},
},
svcConf: &serviceConfig{
healthMonitorDelay: 3,
healthMonitorTimeout: 5,
healthMonitorMaxRetries: 1,
healthMonitorMaxRetriesDown: 2,
healthCheckNodePort: 0,
},
port: corev1.ServicePort{
Protocol: corev1.ProtocolTCP,
},
},
want: v2monitors.CreateOpts{
Name: "using node port zero",
Type: "TCP",
Delay: 3,
Timeout: 5,
MaxRetries: 1,
MaxRetriesDown: 2,
},
},
{
name: "using tcp protocol with not-ovn provider",
testArg: testArg{
lbaas: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "amphora",
},
lb: &gophercloud.ServiceClient{},
},
},
svcConf: &serviceConfig{
healthMonitorDelay: 3,
healthMonitorTimeout: 4,
healthMonitorMaxRetries: 1,
healthMonitorMaxRetriesDown: 5,
healthCheckNodePort: 310000,
},
port: corev1.ServicePort{
Protocol: corev1.ProtocolTCP,
},
},
want: v2monitors.CreateOpts{
Name: "using tcp protocol with not-ovn provider",
Type: "HTTP",
Delay: 3,
Timeout: 4,
MaxRetries: 1,
MaxRetriesDown: 5,

URLPath: "/healthz",
HTTPMethod: "GET",
ExpectedCodes: "200",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.testArg.lbaas.buildMonitorCreateOpts(tt.testArg.svcConf, tt.testArg.port, tt.name)
assert.Equal(t, tt.want, result)
})
}
}

0 comments on commit b1d415f

Please sign in to comment.