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"
|
2023-04-17 08:56:36 +00:00
|
|
|
gatev1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
|
2020-12-15 15:40:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStatusEquals(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
2023-04-17 08:56:36 +00:00
|
|
|
statusA gatev1alpha2.GatewayStatus
|
|
|
|
statusB gatev1alpha2.GatewayStatus
|
2020-12-15 15:40:05 +00:00
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Empty",
|
2023-04-17 08:56:36 +00:00
|
|
|
statusA: gatev1alpha2.GatewayStatus{},
|
|
|
|
statusB: gatev1alpha2.GatewayStatus{},
|
2020-12-15 15:40:05 +00:00
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Same status",
|
2023-04-17 08:56:36 +00:00
|
|
|
statusA: gatev1alpha2.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Reason: "foobar",
|
|
|
|
},
|
|
|
|
},
|
2023-04-17 08:56:36 +00:00
|
|
|
Listeners: []gatev1alpha2.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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-04-17 08:56:36 +00:00
|
|
|
statusB: gatev1alpha2.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Reason: "foobar",
|
|
|
|
},
|
|
|
|
},
|
2023-04-17 08:56:36 +00:00
|
|
|
Listeners: []gatev1alpha2.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",
|
2023-04-17 08:56:36 +00:00
|
|
|
statusA: gatev1alpha2.GatewayStatus{
|
|
|
|
Listeners: []gatev1alpha2.ListenerStatus{},
|
2020-12-15 15:40:05 +00:00
|
|
|
},
|
2023-04-17 08:56:36 +00:00
|
|
|
statusB: gatev1alpha2.GatewayStatus{
|
|
|
|
Listeners: []gatev1alpha2.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Gateway conditions length not equal",
|
2023-04-17 08:56:36 +00:00
|
|
|
statusA: gatev1alpha2.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{},
|
|
|
|
},
|
2023-04-17 08:56:36 +00:00
|
|
|
statusB: gatev1alpha2.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Gateway conditions different types",
|
2023-04-17 08:56:36 +00:00
|
|
|
statusA: gatev1alpha2.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-04-17 08:56:36 +00:00
|
|
|
statusB: gatev1alpha2.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobir",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Gateway conditions same types but different reason",
|
2023-04-17 08:56:36 +00:00
|
|
|
statusA: gatev1alpha2.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-04-17 08:56:36 +00:00
|
|
|
statusB: gatev1alpha2.GatewayStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
Reason: "Another reason",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Gateway listeners conditions length",
|
2023-04-17 08:56:36 +00:00
|
|
|
statusA: gatev1alpha2.GatewayStatus{
|
|
|
|
Listeners: []gatev1alpha2.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{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-04-17 08:56:36 +00:00
|
|
|
statusB: gatev1alpha2.GatewayStatus{
|
|
|
|
Listeners: []gatev1alpha2.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",
|
2023-04-17 08:56:36 +00:00
|
|
|
statusA: gatev1alpha2.GatewayStatus{
|
|
|
|
Listeners: []gatev1alpha2.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{
|
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-04-17 08:56:36 +00:00
|
|
|
statusB: gatev1alpha2.GatewayStatus{
|
|
|
|
Listeners: []gatev1alpha2.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",
|
2023-04-17 08:56:36 +00:00
|
|
|
statusA: gatev1alpha2.GatewayStatus{
|
|
|
|
Listeners: []gatev1alpha2.ListenerStatus{
|
2020-12-15 15:40:05 +00:00
|
|
|
{
|
|
|
|
Conditions: []metav1.Condition{
|
|
|
|
{
|
|
|
|
Type: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-04-17 08:56:36 +00:00
|
|
|
statusB: gatev1alpha2.GatewayStatus{
|
|
|
|
Listeners: []gatev1alpha2.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",
|
2023-04-17 08:56:36 +00:00
|
|
|
statusA: gatev1alpha2.GatewayStatus{
|
|
|
|
Listeners: []gatev1alpha2.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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-04-17 08:56:36 +00:00
|
|
|
statusB: gatev1alpha2.GatewayStatus{
|
|
|
|
Listeners: []gatev1alpha2.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,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
test := test
|
|
|
|
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
result := statusEquals(test.statusA, test.statusB)
|
|
|
|
|
|
|
|
assert.Equal(t, test.expected, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|