istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/config/kube/gateway/conditions_test.go (about) 1 // Copyright Istio Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package gateway 16 17 import ( 18 "reflect" 19 "testing" 20 21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 k8s "sigs.k8s.io/gateway-api/apis/v1beta1" 23 24 "istio.io/istio/pilot/pkg/features" 25 "istio.io/istio/pkg/config" 26 "istio.io/istio/pkg/config/schema/gvk" 27 ) 28 29 func TestCreateRouteStatus(t *testing.T) { 30 lastTransitionTime := metav1.Now() 31 parentRef := httpRouteSpec.ParentRefs[0] 32 parentStatus := []k8s.RouteParentStatus{ 33 { 34 ParentRef: parentRef, 35 ControllerName: k8s.GatewayController("another-gateway-controller"), 36 Conditions: []metav1.Condition{ 37 {Type: "foo", Status: "bar"}, 38 }, 39 }, 40 { 41 ParentRef: parentRef, 42 ControllerName: k8s.GatewayController(features.ManagedGatewayController), 43 Conditions: []metav1.Condition{ 44 { 45 Type: string(k8s.RouteReasonAccepted), 46 Status: metav1.ConditionTrue, 47 ObservedGeneration: 1, 48 LastTransitionTime: lastTransitionTime, 49 Message: "Route was valid", 50 }, 51 { 52 Type: string(k8s.RouteConditionResolvedRefs), 53 Status: metav1.ConditionTrue, 54 ObservedGeneration: 1, 55 LastTransitionTime: lastTransitionTime, 56 Message: "All references resolved", 57 }, 58 }, 59 }, 60 } 61 62 httpRoute := config.Config{ 63 Meta: config.Meta{ 64 GroupVersionKind: gvk.HTTPRoute, 65 Namespace: "foo", 66 Name: "bar", 67 Generation: 1, 68 }, 69 Spec: &httpRouteSpec, 70 Status: &k8s.HTTPRouteStatus{ 71 RouteStatus: k8s.RouteStatus{ 72 Parents: parentStatus, 73 }, 74 }, 75 } 76 77 type args struct { 78 gateways []RouteParentResult 79 obj config.Config 80 current []k8s.RouteParentStatus 81 } 82 tests := []struct { 83 name string 84 args args 85 wantEqual bool 86 }{ 87 { 88 name: "no error", 89 args: args{ 90 gateways: []RouteParentResult{{OriginalReference: parentRef}}, 91 obj: httpRoute, 92 current: parentStatus, 93 }, 94 wantEqual: true, 95 }, 96 { 97 name: "route status error", 98 args: args{ 99 gateways: []RouteParentResult{{OriginalReference: parentRef, RouteError: &ConfigError{ 100 Reason: ConfigErrorReason(k8s.RouteReasonRefNotPermitted), 101 }}}, 102 obj: httpRoute, 103 current: parentStatus, 104 }, 105 wantEqual: false, 106 }, 107 } 108 for _, tt := range tests { 109 t.Run(tt.name, func(t *testing.T) { 110 got := createRouteStatus(tt.args.gateways, tt.args.obj, tt.args.current) 111 equal := reflect.DeepEqual(got, tt.args.current) 112 if equal != tt.wantEqual { 113 t.Errorf("route status: old: %+v, new: %+v", tt.args.current, got) 114 } 115 }) 116 } 117 }