2023-03-27 10:14:05 +00:00
|
|
|
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"
|
2023-03-27 10:14:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
2023-03-27 10:14:05 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-04-03 08:06:06 +00:00
|
|
|
expected := []netv1.IngressLoadBalancerIngress{
|
2023-03-27 10:14:05 +00:00
|
|
|
{
|
|
|
|
IP: "132456",
|
|
|
|
Hostname: "foo",
|
2023-04-03 08:06:06 +00:00
|
|
|
Ports: []netv1.IngressPortStatus{
|
2023-03-27 10:14:05 +00:00
|
|
|
{
|
|
|
|
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)
|
2023-03-27 10:14:05 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-04-03 08:06:06 +00:00
|
|
|
expected := &netv1.IngressLoadBalancerIngress{
|
2023-03-27 10:14:05 +00:00
|
|
|
IP: "132456",
|
|
|
|
Hostname: "foo",
|
2023-04-03 08:06:06 +00:00
|
|
|
Ports: []netv1.IngressPortStatus{
|
2023-03-27 10:14:05 +00:00
|
|
|
{
|
|
|
|
Port: 123,
|
|
|
|
Protocol: "https",
|
|
|
|
Error: ptr("test"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ptr[T any](v T) *T {
|
|
|
|
return &v
|
|
|
|
}
|