2020-12-15 15:40:05 +00:00
|
|
|
package gateway
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2024-01-09 09:28:05 +00:00
|
|
|
gatev1 "sigs.k8s.io/gateway-api/apis/v1"
|
2020-12-15 15:40:05 +00:00
|
|
|
)
|
|
|
|
|
2024-05-28 12:30:04 +00:00
|
|
|
func Test_gatewayStatusEquals(t *testing.T) {
|
2020-12-15 15:40:05 +00:00
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
2024-01-09 09:28:05 +00:00
|
|
|
statusA gatev1.GatewayStatus
|
|
|
|
statusB gatev1.GatewayStatus
|
2020-12-15 15:40:05 +00:00
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Empty",
|
2024-01-09 09:28:05 +00:00
|
|
|
statusA: gatev1.GatewayStatus{},
|
|
|
|
statusB: gatev1.GatewayStatus{},
|
2020-12-15 15:40:05 +00:00
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Same status",
|
2024-01-09 09:28:05 +00:00
|
|
|
statusA: gatev1.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Reason: "foobar",
|
|
|
|
},
|
|
|
|
},
|
2024-01-09 09:28:05 +00:00
|
|
|
Listeners: []gatev1.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{
|
2021-11-09 10:34:06 +00:00
|
|
|
Name: "foo",
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Reason: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-09 09:28:05 +00:00
|
|
|
statusB: gatev1.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Reason: "foobar",
|
|
|
|
},
|
|
|
|
},
|
2024-01-09 09:28:05 +00:00
|
|
|
Listeners: []gatev1.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{
|
2021-11-09 10:34:06 +00:00
|
|
|
Name: "foo",
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Reason: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Listeners length not equal",
|
2024-01-09 09:28:05 +00:00
|
|
|
statusA: gatev1.GatewayStatus{
|
|
|
|
Listeners: []gatev1.ListenerStatus{},
|
2020-12-15 15:40:05 +00:00
|
|
|
},
|
2024-01-09 09:28:05 +00:00
|
|
|
statusB: gatev1.GatewayStatus{
|
|
|
|
Listeners: []gatev1.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Gateway conditions length not equal",
|
2024-01-09 09:28:05 +00:00
|
|
|
statusA: gatev1.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{},
|
|
|
|
},
|
2024-01-09 09:28:05 +00:00
|
|
|
statusB: gatev1.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Gateway conditions different types",
|
2024-01-09 09:28:05 +00:00
|
|
|
statusA: gatev1.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-09 09:28:05 +00:00
|
|
|
statusB: gatev1.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobir",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Gateway conditions same types but different reason",
|
2024-01-09 09:28:05 +00:00
|
|
|
statusA: gatev1.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-09 09:28:05 +00:00
|
|
|
statusB: gatev1.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Reason: "Another reason",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Gateway listeners conditions length",
|
2024-01-09 09:28:05 +00:00
|
|
|
statusA: gatev1.GatewayStatus{
|
|
|
|
Listeners: []gatev1.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{
|
2021-11-09 10:34:06 +00:00
|
|
|
Name: "foo",
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-09 09:28:05 +00:00
|
|
|
statusB: gatev1.GatewayStatus{
|
|
|
|
Listeners: []gatev1.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{
|
2021-11-09 10:34:06 +00:00
|
|
|
Name: "foo",
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Gateway listeners conditions same types but different status",
|
2024-01-09 09:28:05 +00:00
|
|
|
statusA: gatev1.GatewayStatus{
|
|
|
|
Listeners: []gatev1.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{
|
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-09 09:28:05 +00:00
|
|
|
statusB: gatev1.GatewayStatus{
|
|
|
|
Listeners: []gatev1.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{
|
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Status: "Another status",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Gateway listeners conditions same types but different message",
|
2024-01-09 09:28:05 +00:00
|
|
|
statusA: gatev1.GatewayStatus{
|
|
|
|
Listeners: []gatev1.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{
|
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-09 09:28:05 +00:00
|
|
|
statusB: gatev1.GatewayStatus{
|
|
|
|
Listeners: []gatev1.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{
|
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Message: "Another status",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
2021-11-09 10:34:06 +00:00
|
|
|
desc: "Gateway listeners conditions same types/reason but different names",
|
2024-01-09 09:28:05 +00:00
|
|
|
statusA: gatev1.GatewayStatus{
|
|
|
|
Listeners: []gatev1.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{
|
2021-11-09 10:34:06 +00:00
|
|
|
Name: "foo",
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Reason: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-09 09:28:05 +00:00
|
|
|
statusB: gatev1.GatewayStatus{
|
|
|
|
Listeners: []gatev1.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{
|
2021-11-09 10:34:06 +00:00
|
|
|
Name: "bar",
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Reason: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
2024-05-28 12:30:04 +00:00
|
|
|
{
|
|
|
|
desc: "Gateway listeners with same conditions but different number of attached routes",
|
|
|
|
statusA: gatev1.GatewayStatus{
|
|
|
|
Listeners: []gatev1.ListenerStatus{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
AttachedRoutes: 1,
|
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Reason: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
statusB: gatev1.GatewayStatus{
|
|
|
|
Listeners: []gatev1.ListenerStatus{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
AttachedRoutes: 2,
|
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Reason: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
2020-12-15 15:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2024-07-29 13:48:05 +00:00
|
|
|
result := gatewayStatusEqual(test.statusA, test.statusB)
|
2020-12-15 15:40:05 +00:00
|
|
|
|
|
|
|
assert.Equal(t, test.expected, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|