test/integration: add helper function serviceHasNodePorts for service load balancer tests

Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>
This commit is contained in:
Andrew Sy Kim 2020-11-23 22:29:41 -05:00
parent c1285ac83b
commit a5aba23813

View File

@ -70,14 +70,7 @@ func Test_ServiceLoadBalancerDisableAllocateNodePorts(t *testing.T) {
t.Fatalf("Error creating test service: %v", err) t.Fatalf("Error creating test service: %v", err)
} }
foundNodePorts := false if serviceHasNodePorts(service) {
for _, port := range service.Spec.Ports {
if port.NodePort > 0 {
foundNodePorts = true
}
}
if foundNodePorts {
t.Error("found node ports when none was expected") t.Error("found node ports when none was expected")
} }
} }
@ -121,14 +114,7 @@ func Test_ServiceLoadBalancerEnableThenDisableAllocatedNodePorts(t *testing.T) {
t.Fatalf("Error creating test service: %v", err) t.Fatalf("Error creating test service: %v", err)
} }
foundNodePorts := false if !serviceHasNodePorts(service) {
for _, port := range service.Spec.Ports {
if port.NodePort > 0 {
foundNodePorts = true
}
}
if !foundNodePorts {
t.Error("expected node ports but found none") t.Error("expected node ports but found none")
} }
@ -138,14 +124,17 @@ func Test_ServiceLoadBalancerEnableThenDisableAllocatedNodePorts(t *testing.T) {
t.Fatalf("Error updating test service: %v", err) t.Fatalf("Error updating test service: %v", err)
} }
foundNodePorts = false if !serviceHasNodePorts(service) {
for _, port := range service.Spec.Ports {
if port.NodePort > 0 {
foundNodePorts = true
}
}
if !foundNodePorts {
t.Error("node ports were unexpectedly deallocated") t.Error("node ports were unexpectedly deallocated")
} }
} }
func serviceHasNodePorts(svc *corev1.Service) bool {
for _, port := range svc.Spec.Ports {
if port.NodePort > 0 {
return true
}
}
return false
}