istio

Форк
0
/
conditions_test.go 
110 строк · 2.9 Кб
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(features.ManagedGatewayController),
36
			Conditions: []metav1.Condition{
37
				{
38
					Type:               string(k8s.RouteReasonAccepted),
39
					Status:             metav1.ConditionTrue,
40
					ObservedGeneration: 1,
41
					LastTransitionTime: lastTransitionTime,
42
					Message:            "Route was valid",
43
				},
44
				{
45
					Type:               string(k8s.RouteConditionResolvedRefs),
46
					Status:             metav1.ConditionTrue,
47
					ObservedGeneration: 1,
48
					LastTransitionTime: lastTransitionTime,
49
					Message:            "All references resolved",
50
				},
51
			},
52
		},
53
	}
54

55
	httpRoute := config.Config{
56
		Meta: config.Meta{
57
			GroupVersionKind: gvk.HTTPRoute,
58
			Namespace:        "foo",
59
			Name:             "bar",
60
			Generation:       1,
61
		},
62
		Spec: &httpRouteSpec,
63
		Status: &k8s.HTTPRouteStatus{
64
			RouteStatus: k8s.RouteStatus{
65
				Parents: parentStatus,
66
			},
67
		},
68
	}
69

70
	type args struct {
71
		gateways []RouteParentResult
72
		obj      config.Config
73
		current  []k8s.RouteParentStatus
74
	}
75
	tests := []struct {
76
		name      string
77
		args      args
78
		wantEqual bool
79
	}{
80
		{
81
			name: "no error",
82
			args: args{
83
				gateways: []RouteParentResult{{OriginalReference: parentRef}},
84
				obj:      httpRoute,
85
				current:  parentStatus,
86
			},
87
			wantEqual: true,
88
		},
89
		{
90
			name: "route status error",
91
			args: args{
92
				gateways: []RouteParentResult{{OriginalReference: parentRef, RouteError: &ConfigError{
93
					Reason: ConfigErrorReason(k8s.RouteReasonRefNotPermitted),
94
				}}},
95
				obj:     httpRoute,
96
				current: parentStatus,
97
			},
98
			wantEqual: false,
99
		},
100
	}
101
	for _, tt := range tests {
102
		t.Run(tt.name, func(t *testing.T) {
103
			got := createRouteStatus(tt.args.gateways, tt.args.obj, tt.args.current)
104
			equal := reflect.DeepEqual(got, tt.args.current)
105
			if equal != tt.wantEqual {
106
				t.Errorf("route status: old: %+v, new: %+v", tt.args.current, got)
107
			}
108
		})
109
	}
110
}
111

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.