traefik/pkg/provider/kubernetes/ingress/convert_test.go

152 lines
2.8 KiB
Go
Raw Normal View History

package ingress
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
2023-04-03 08:06:06 +00:00
netv1 "k8s.io/api/networking/v1"
netv1beta1 "k8s.io/api/networking/v1beta1"
)
func Test_convertSlice_corev1_to_networkingv1(t *testing.T) {
g := []corev1.LoadBalancerIngress{
{
IP: "132456",
Hostname: "foo",
Ports: []corev1.PortStatus{
{
Port: 123,
Protocol: "https",
Error: ptr("test"),
},
},
},
}
2023-04-03 08:06:06 +00:00
actual, err := convertSlice[netv1.IngressLoadBalancerIngress](g)
require.NoError(t, err)
2023-04-03 08:06:06 +00:00
expected := []netv1.IngressLoadBalancerIngress{
{
IP: "132456",
Hostname: "foo",
2023-04-03 08:06:06 +00:00
Ports: []netv1.IngressPortStatus{
{
Port: 123,
Protocol: "https",
Error: ptr("test"),
},
},
},
}
assert.Equal(t, expected, actual)
}
func Test_convertSlice_networkingv1beta1_to_networkingv1(t *testing.T) {
2023-04-03 08:06:06 +00:00
g := []netv1beta1.IngressLoadBalancerIngress{
{
IP: "132456",
Hostname: "foo",
2023-04-03 08:06:06 +00:00
Ports: []netv1beta1.IngressPortStatus{
{
Port: 123,
Protocol: "https",
Error: ptr("test"),
},
},
},
}
2023-04-03 08:06:06 +00:00
actual, err := convertSlice[netv1.IngressLoadBalancerIngress](g)
require.NoError(t, err)
2023-04-03 08:06:06 +00:00
expected := []netv1.IngressLoadBalancerIngress{
{
IP: "132456",
Hostname: "foo",
2023-04-03 08:06:06 +00:00
Ports: []netv1.IngressPortStatus{
{
Port: 123,
Protocol: "https",
Error: ptr("test"),
},
},
},
}
assert.Equal(t, expected, actual)
}
func Test_convertSlice_networkingv1_to_networkingv1beta1(t *testing.T) {
2023-04-03 08:06:06 +00:00
g := []netv1.IngressLoadBalancerIngress{
{
IP: "132456",
Hostname: "foo",
2023-04-03 08:06:06 +00:00
Ports: []netv1.IngressPortStatus{
{
Port: 123,
Protocol: "https",
Error: ptr("test"),
},
},
},
}
2023-04-03 08:06:06 +00:00
actual, err := convertSlice[netv1beta1.IngressLoadBalancerIngress](g)
require.NoError(t, err)
2023-04-03 08:06:06 +00:00
expected := []netv1beta1.IngressLoadBalancerIngress{
{
IP: "132456",
Hostname: "foo",
2023-04-03 08:06:06 +00:00
Ports: []netv1beta1.IngressPortStatus{
{
Port: 123,
Protocol: "https",
Error: ptr("test"),
},
},
},
}
assert.Equal(t, expected, actual)
}
func Test_convert(t *testing.T) {
g := &corev1.LoadBalancerIngress{
IP: "132456",
Hostname: "foo",
Ports: []corev1.PortStatus{
{
Port: 123,
Protocol: "https",
Error: ptr("test"),
},
},
}
2023-04-03 08:06:06 +00:00
actual, err := convert[netv1.IngressLoadBalancerIngress](g)
require.NoError(t, err)
2023-04-03 08:06:06 +00:00
expected := &netv1.IngressLoadBalancerIngress{
IP: "132456",
Hostname: "foo",
2023-04-03 08:06:06 +00:00
Ports: []netv1.IngressPortStatus{
{
Port: 123,
Protocol: "https",
Error: ptr("test"),
},
},
}
assert.Equal(t, expected, actual)
}
func ptr[T any](v T) *T {
return &v
}