@@ -31,6 +31,29 @@ func TestBuildReferencedServices(t *testing.T) {
31
31
},
32
32
}
33
33
34
+ normalGRPCRoute := & GRPCRoute {
35
+ ParentRefs : []ParentRef {
36
+ {
37
+ Attachment : & ParentRefAttachmentStatus {
38
+ Attached : true ,
39
+ },
40
+ },
41
+ },
42
+ Valid : true ,
43
+ Rules : []Rule {
44
+ {
45
+ BackendRefs : []BackendRef {
46
+ {
47
+ SvcNsName : types.NamespacedName {Namespace : "banana-ns" , Name : "grpc-service" },
48
+ Weight : 1 ,
49
+ },
50
+ },
51
+ ValidMatches : true ,
52
+ ValidFilters : true ,
53
+ },
54
+ },
55
+ }
56
+
34
57
validRouteTwoServicesOneRule := & HTTPRoute {
35
58
ParentRefs : []ParentRef {
36
59
{
@@ -114,6 +137,29 @@ func TestBuildReferencedServices(t *testing.T) {
114
137
},
115
138
}
116
139
140
+ invalidGRPCRoute := & GRPCRoute {
141
+ ParentRefs : []ParentRef {
142
+ {
143
+ Attachment : & ParentRefAttachmentStatus {
144
+ Attached : true ,
145
+ },
146
+ },
147
+ },
148
+ Valid : false ,
149
+ Rules : []Rule {
150
+ {
151
+ BackendRefs : []BackendRef {
152
+ {
153
+ SvcNsName : types.NamespacedName {Namespace : "service-ns" , Name : "grpc-service" },
154
+ Weight : 1 ,
155
+ },
156
+ },
157
+ ValidMatches : true ,
158
+ ValidFilters : true ,
159
+ },
160
+ },
161
+ }
162
+
117
163
unattachedRoute := & HTTPRoute {
118
164
ParentRefs : []ParentRef {
119
165
{
@@ -192,22 +238,27 @@ func TestBuildReferencedServices(t *testing.T) {
192
238
}
193
239
194
240
tests := []struct {
195
- routes map [types.NamespacedName ]* HTTPRoute
196
- exp map [types.NamespacedName ]struct {}
197
- name string
241
+ httpRoutes map [types.NamespacedName ]* HTTPRoute
242
+ grpcRoutes map [types.NamespacedName ]* GRPCRoute
243
+ exp map [types.NamespacedName ]struct {}
244
+ name string
198
245
}{
199
246
{
200
247
name : "normal route" ,
201
- routes : map [types.NamespacedName ]* HTTPRoute {
248
+ httpRoutes : map [types.NamespacedName ]* HTTPRoute {
202
249
{Name : "normal-route" }: normalRoute ,
203
250
},
251
+ grpcRoutes : map [types.NamespacedName ]* GRPCRoute {
252
+ {Name : "normal-grpc-route" }: normalGRPCRoute ,
253
+ },
204
254
exp : map [types.NamespacedName ]struct {}{
205
- {Namespace : "banana-ns" , Name : "service" }: {},
255
+ {Namespace : "banana-ns" , Name : "service" }: {},
256
+ {Namespace : "banana-ns" , Name : "grpc-service" }: {},
206
257
},
207
258
},
208
259
{
209
260
name : "route with two services in one Rule" ,
210
- routes : map [types.NamespacedName ]* HTTPRoute {
261
+ httpRoutes : map [types.NamespacedName ]* HTTPRoute {
211
262
{Name : "two-svc-one-rule" }: validRouteTwoServicesOneRule ,
212
263
},
213
264
exp : map [types.NamespacedName ]struct {}{
@@ -217,7 +268,7 @@ func TestBuildReferencedServices(t *testing.T) {
217
268
},
218
269
{
219
270
name : "route with one service per rule" ,
220
- routes : map [types.NamespacedName ]* HTTPRoute {
271
+ httpRoutes : map [types.NamespacedName ]* HTTPRoute {
221
272
{Name : "one-svc-per-rule" }: validRouteTwoServicesTwoRules ,
222
273
},
223
274
exp : map [types.NamespacedName ]struct {}{
@@ -227,7 +278,7 @@ func TestBuildReferencedServices(t *testing.T) {
227
278
},
228
279
{
229
280
name : "two valid routes with same services" ,
230
- routes : map [types.NamespacedName ]* HTTPRoute {
281
+ httpRoutes : map [types.NamespacedName ]* HTTPRoute {
231
282
{Name : "one-svc-per-rule" }: validRouteTwoServicesTwoRules ,
232
283
{Name : "two-svc-one-rule" }: validRouteTwoServicesOneRule ,
233
284
},
@@ -238,7 +289,7 @@ func TestBuildReferencedServices(t *testing.T) {
238
289
},
239
290
{
240
291
name : "two valid routes with different services" ,
241
- routes : map [types.NamespacedName ]* HTTPRoute {
292
+ httpRoutes : map [types.NamespacedName ]* HTTPRoute {
242
293
{Name : "one-svc-per-rule" }: validRouteTwoServicesTwoRules ,
243
294
{Name : "normal-route" }: normalRoute ,
244
295
},
@@ -249,22 +300,25 @@ func TestBuildReferencedServices(t *testing.T) {
249
300
},
250
301
},
251
302
{
252
- name : "invalid route " ,
253
- routes : map [types.NamespacedName ]* HTTPRoute {
303
+ name : "invalid routes " ,
304
+ httpRoutes : map [types.NamespacedName ]* HTTPRoute {
254
305
{Name : "invalid-route" }: invalidRoute ,
255
306
},
307
+ grpcRoutes : map [types.NamespacedName ]* GRPCRoute {
308
+ {Name : "invalid-grpc" }: invalidGRPCRoute ,
309
+ },
256
310
exp : nil ,
257
311
},
258
312
{
259
313
name : "unattached route" ,
260
- routes : map [types.NamespacedName ]* HTTPRoute {
314
+ httpRoutes : map [types.NamespacedName ]* HTTPRoute {
261
315
{Name : "unattached-route" }: unattachedRoute ,
262
316
},
263
317
exp : nil ,
264
318
},
265
319
{
266
320
name : "combination of valid and invalid routes" ,
267
- routes : map [types.NamespacedName ]* HTTPRoute {
321
+ httpRoutes : map [types.NamespacedName ]* HTTPRoute {
268
322
{Name : "normal-route" }: normalRoute ,
269
323
{Name : "invalid-route" }: invalidRoute ,
270
324
},
@@ -274,7 +328,7 @@ func TestBuildReferencedServices(t *testing.T) {
274
328
},
275
329
{
276
330
name : "route with many parentRefs and one is attached" ,
277
- routes : map [types.NamespacedName ]* HTTPRoute {
331
+ httpRoutes : map [types.NamespacedName ]* HTTPRoute {
278
332
{Name : "multiple-parent-ref-route" }: attachedRouteWithManyParentRefs ,
279
333
},
280
334
exp : map [types.NamespacedName ]struct {}{
@@ -283,19 +337,17 @@ func TestBuildReferencedServices(t *testing.T) {
283
337
},
284
338
{
285
339
name : "valid route no service nsname" ,
286
- routes : map [types.NamespacedName ]* HTTPRoute {
340
+ httpRoutes : map [types.NamespacedName ]* HTTPRoute {
287
341
{Name : "no-service-nsname" }: validRouteNoServiceNsName ,
288
342
},
289
343
exp : nil ,
290
344
},
291
345
}
292
346
293
- grpcRoutes := map [types.NamespacedName ]* GRPCRoute {}
294
-
295
347
for _ , test := range tests {
296
348
t .Run (test .name , func (t * testing.T ) {
297
349
g := NewWithT (t )
298
- g .Expect (buildReferencedServices (test .routes , grpcRoutes )).To (Equal (test .exp ))
350
+ g .Expect (buildReferencedServices (test .httpRoutes , test . grpcRoutes )).To (Equal (test .exp ))
299
351
})
300
352
}
301
353
}
0 commit comments