@@ -13,11 +13,16 @@ func TestClientSettingsPoliciesTargetRef(t *testing.T) {
13
13
"GRPCRoute" : true ,
14
14
}
15
15
16
- testInvalidTargetRefs (t , allowedKinds )
17
16
testValidTargetRefs (t , allowedKinds )
17
+ testInvalidTargetRefs (t , allowedKinds )
18
18
}
19
19
20
- func testInvalidTargetRefs (t * testing.T , allowedKinds map [string ]bool ) {
20
+ func TestClientSettingsPoliciesTargetRefGroup (t * testing.T ) {
21
+ testValidTargetRefGroup (t )
22
+ testInvalidTargetRefGroup (t )
23
+ }
24
+
25
+ func testValidTargetRefs (t * testing.T , allowedKinds map [string ]bool ) {
21
26
t .Helper ()
22
27
23
28
tests := []struct {
@@ -29,15 +34,23 @@ func testInvalidTargetRefs(t *testing.T, allowedKinds map[string]bool) {
29
34
name : "Validate TargetRef is of an allowed kind" ,
30
35
wantErrors : "TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'" ,
31
36
targetRef : gatewayv1alpha2.LocalPolicyTargetReference {
32
- Kind : "InvalidKind " ,
37
+ Kind : "Gateway " ,
33
38
Group : "gateway.networking.k8s.io" ,
34
39
},
35
40
},
36
41
{
37
42
name : "Validate TargetRef is of an allowed kind" ,
38
43
wantErrors : "TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'" ,
39
44
targetRef : gatewayv1alpha2.LocalPolicyTargetReference {
40
- Kind : "TCPRoute" ,
45
+ Kind : "HTTPRoute" ,
46
+ Group : "gateway.networking.k8s.io" ,
47
+ },
48
+ },
49
+ {
50
+ name : "Validate TargetRef is of an allowed kind" ,
51
+ wantErrors : "TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'" ,
52
+ targetRef : gatewayv1alpha2.LocalPolicyTargetReference {
53
+ Kind : "GRPCRoute" ,
41
54
Group : "gateway.networking.k8s.io" ,
42
55
},
43
56
},
@@ -48,15 +61,15 @@ func testInvalidTargetRefs(t *testing.T, allowedKinds map[string]bool) {
48
61
if _ , ok := allowedKinds [string (tt .targetRef .Kind )]; ! ok {
49
62
gotError := "TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'"
50
63
51
- if tt .wantErrors ! = gotError {
64
+ if tt .wantErrors = = gotError {
52
65
t .Errorf ("Test %s failed: got error %q, want %q" , tt .name , gotError , tt .wantErrors )
53
66
}
54
67
}
55
68
})
56
69
}
57
70
}
58
71
59
- func testValidTargetRefs (t * testing.T , allowedKinds map [string ]bool ) {
72
+ func testInvalidTargetRefs (t * testing.T , allowedKinds map [string ]bool ) {
60
73
t .Helper ()
61
74
62
75
tests := []struct {
@@ -68,32 +81,54 @@ func testValidTargetRefs(t *testing.T, allowedKinds map[string]bool) {
68
81
name : "Validate TargetRef is of an allowed kind" ,
69
82
wantErrors : "TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'" ,
70
83
targetRef : gatewayv1alpha2.LocalPolicyTargetReference {
71
- Kind : "Gateway " ,
84
+ Kind : "InvalidKind " ,
72
85
Group : "gateway.networking.k8s.io" ,
73
86
},
74
87
},
75
88
{
76
89
name : "Validate TargetRef is of an allowed kind" ,
77
90
wantErrors : "TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'" ,
78
91
targetRef : gatewayv1alpha2.LocalPolicyTargetReference {
79
- Kind : "HTTPRoute " ,
92
+ Kind : "TCPRoute " ,
80
93
Group : "gateway.networking.k8s.io" ,
81
94
},
82
95
},
96
+ }
97
+
98
+ for _ , tt := range tests {
99
+ t .Run (tt .name , func (t * testing.T ) {
100
+ if _ , ok := allowedKinds [string (tt .targetRef .Kind )]; ! ok {
101
+ gotError := "TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'"
102
+
103
+ if tt .wantErrors != gotError {
104
+ t .Errorf ("Test %s failed: got error %q, want %q" , tt .name , gotError , tt .wantErrors )
105
+ }
106
+ }
107
+ })
108
+ }
109
+ }
110
+
111
+ func testValidTargetRefGroup (t * testing.T ) {
112
+ t .Helper ()
113
+
114
+ tests := []struct {
115
+ name string
116
+ wantErrors string
117
+ targetRefGroup gatewayv1alpha2.LocalPolicyTargetReference
118
+ }{
83
119
{
84
- name : "Validate TargetRef is of an allowed kind" ,
85
- wantErrors : "TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'" ,
86
- targetRef : gatewayv1alpha2.LocalPolicyTargetReference {
87
- Kind : "GRPCRoute" ,
120
+ name : "Validate TargetRef group is gateway.networking.k8s.io" ,
121
+ wantErrors : "TargetRef Group must be gateway.networking.k8s.io" ,
122
+ targetRefGroup : gatewayv1alpha2.LocalPolicyTargetReference {
88
123
Group : "gateway.networking.k8s.io" ,
89
124
},
90
125
},
91
126
}
92
127
93
128
for _ , tt := range tests {
94
129
t .Run (tt .name , func (t * testing.T ) {
95
- if _ , ok := allowedKinds [ string ( tt .targetRef . Kind )]; ! ok {
96
- gotError := "TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute' "
130
+ if tt .targetRefGroup . Group != "gateway.networking.k8s.io" {
131
+ gotError := "TargetRef Group must be gateway.networking.k8s.io "
97
132
98
133
if tt .wantErrors == gotError {
99
134
t .Errorf ("Test %s failed: got error %q, want %q" , tt .name , gotError , tt .wantErrors )
@@ -102,3 +137,40 @@ func testValidTargetRefs(t *testing.T, allowedKinds map[string]bool) {
102
137
})
103
138
}
104
139
}
140
+
141
+ func testInvalidTargetRefGroup (t * testing.T ) {
142
+ t .Helper ()
143
+
144
+ tests := []struct {
145
+ name string
146
+ wantErrors string
147
+ targetRefGroup gatewayv1alpha2.LocalPolicyTargetReference
148
+ }{
149
+ {
150
+ name : "Validate TargetRef group is gateway.networking.k8s.io" ,
151
+ wantErrors : "TargetRef Group must be gateway.networking.k8s.io" ,
152
+ targetRefGroup : gatewayv1alpha2.LocalPolicyTargetReference {
153
+ Group : "invalid.networking.k8s.io" ,
154
+ },
155
+ },
156
+ {
157
+ name : "Validate TargetRef is of an allowed kind" ,
158
+ wantErrors : "TargetRef Group must be gateway.networking.k8s.io" ,
159
+ targetRefGroup : gatewayv1alpha2.LocalPolicyTargetReference {
160
+ Group : "discovery.k8s.io/v1" ,
161
+ },
162
+ },
163
+ }
164
+
165
+ for _ , tt := range tests {
166
+ t .Run (tt .name , func (t * testing.T ) {
167
+ if tt .targetRefGroup .Group != "gateway.networking.k8s.io" {
168
+ gotError := "TargetRef Group must be gateway.networking.k8s.io"
169
+
170
+ if tt .wantErrors != gotError {
171
+ t .Errorf ("Test %s failed: got error %q, want %q" , tt .name , gotError , tt .wantErrors )
172
+ }
173
+ }
174
+ })
175
+ }
176
+ }
0 commit comments