Skip to content

Commit

Permalink
test: buildMonitorCreateOpts
Browse files Browse the repository at this point in the history
  • Loading branch information
majorchork committed Oct 19, 2023
1 parent b4d3df3 commit a3623d6
Showing 1 changed file with 150 additions and 0 deletions.
150 changes: 150 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 @@ -1756,3 +1758,151 @@ func Test_getSubnetID(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 udp with ovn provider",
testArg: testArg{
lbaas: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "ovn",
},
},
},
svcConf: &serviceConfig{
healthMonitorDelay: 8,
healthMonitorTimeout: 4,
healthMonitorMaxRetries: 3,
healthMonitorMaxRetriesDown: 2,
healthCheckNodePort: 32000,
},
port: corev1.ServicePort{
Protocol: corev1.ProtocolUDP,
},
},
want: v2monitors.CreateOpts{
Name: "using udp with ovn provider",
Type: "UDP-CONNECT",
Delay: 8,
Timeout: 4,
MaxRetries: 3,
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 a3623d6

Please sign in to comment.