@@ -181,12 +181,14 @@ func TestCreateServers(t *testing.T) {
181
181
{
182
182
Path : & v1beta1.HTTPPathMatch {
183
183
Value : helpers .GetStringPointer ("/" ),
184
+ Type : helpers .GetPointer (v1beta1 .PathMatchPathPrefix ),
184
185
},
185
186
Method : helpers .GetHTTPMethodPointer (v1beta1 .HTTPMethodPost ),
186
187
},
187
188
{
188
189
Path : & v1beta1.HTTPPathMatch {
189
190
Value : helpers .GetStringPointer ("/" ),
191
+ Type : helpers .GetPointer (v1beta1 .PathMatchPathPrefix ),
190
192
},
191
193
Method : helpers .GetHTTPMethodPointer (v1beta1 .HTTPMethodPatch ),
192
194
},
@@ -195,6 +197,7 @@ func TestCreateServers(t *testing.T) {
195
197
Value : helpers .GetStringPointer (
196
198
"/" , // should generate an "any" httpmatch since other matches exists for /
197
199
),
200
+ Type : helpers .GetPointer (v1beta1 .PathMatchPathPrefix ),
198
201
},
199
202
},
200
203
},
@@ -205,6 +208,7 @@ func TestCreateServers(t *testing.T) {
205
208
{
206
209
Path : & v1beta1.HTTPPathMatch {
207
210
Value : helpers .GetStringPointer ("/test" ),
211
+ Type : helpers .GetPointer (v1beta1 .PathMatchPathPrefix ),
208
212
},
209
213
Method : helpers .GetHTTPMethodPointer (v1beta1 .HTTPMethodGet ),
210
214
Headers : []v1beta1.HTTPHeaderMatch {
@@ -245,6 +249,7 @@ func TestCreateServers(t *testing.T) {
245
249
{
246
250
Path : & v1beta1.HTTPPathMatch {
247
251
Value : helpers .GetStringPointer ("/path-only" ),
252
+ Type : helpers .GetPointer (v1beta1 .PathMatchPathPrefix ),
248
253
},
249
254
},
250
255
},
@@ -255,6 +260,7 @@ func TestCreateServers(t *testing.T) {
255
260
{
256
261
Path : & v1beta1.HTTPPathMatch {
257
262
Value : helpers .GetStringPointer ("/redirect-implicit-port" ),
263
+ Type : helpers .GetPointer (v1beta1 .PathMatchPathPrefix ),
258
264
},
259
265
},
260
266
},
@@ -266,6 +272,7 @@ func TestCreateServers(t *testing.T) {
266
272
{
267
273
Path : & v1beta1.HTTPPathMatch {
268
274
Value : helpers .GetStringPointer ("/redirect-explicit-port" ),
275
+ Type : helpers .GetPointer (v1beta1 .PathMatchPathPrefix ),
269
276
},
270
277
},
271
278
},
@@ -277,10 +284,34 @@ func TestCreateServers(t *testing.T) {
277
284
{
278
285
Path : & v1beta1.HTTPPathMatch {
279
286
Value : helpers .GetPointer ("/invalid-filter" ),
287
+ Type : helpers .GetPointer (v1beta1 .PathMatchPathPrefix ),
280
288
},
281
289
},
282
290
},
283
291
},
292
+ {
293
+ // A match using type Exact
294
+ Matches : []v1beta1.HTTPRouteMatch {
295
+ {
296
+ Path : & v1beta1.HTTPPathMatch {
297
+ Value : helpers .GetPointer ("/exact" ),
298
+ Type : helpers .GetPointer (v1beta1 .PathMatchExact ),
299
+ },
300
+ },
301
+ },
302
+ },
303
+ {
304
+ // A match using type Exact with method
305
+ Matches : []v1beta1.HTTPRouteMatch {
306
+ {
307
+ Path : & v1beta1.HTTPPathMatch {
308
+ Value : helpers .GetPointer ("/test" ),
309
+ Type : helpers .GetPointer (v1beta1 .PathMatchExact ),
310
+ },
311
+ Method : helpers .GetHTTPMethodPointer (v1beta1 .HTTPMethodGet ),
312
+ },
313
+ },
314
+ },
284
315
},
285
316
},
286
317
}
@@ -338,7 +369,8 @@ func TestCreateServers(t *testing.T) {
338
369
339
370
cafePathRules := []dataplane.PathRule {
340
371
{
341
- Path : "/" ,
372
+ Path : "/" ,
373
+ PathType : dataplane .PathTypePrefix ,
342
374
MatchRules : []dataplane.MatchRule {
343
375
{
344
376
MatchIdx : 0 ,
@@ -361,7 +393,8 @@ func TestCreateServers(t *testing.T) {
361
393
},
362
394
},
363
395
{
364
- Path : "/test" ,
396
+ Path : "/test" ,
397
+ PathType : dataplane .PathTypePrefix ,
365
398
MatchRules : []dataplane.MatchRule {
366
399
{
367
400
MatchIdx : 0 ,
@@ -372,7 +405,8 @@ func TestCreateServers(t *testing.T) {
372
405
},
373
406
},
374
407
{
375
- Path : "/path-only" ,
408
+ Path : "/path-only" ,
409
+ PathType : dataplane .PathTypePrefix ,
376
410
MatchRules : []dataplane.MatchRule {
377
411
{
378
412
MatchIdx : 0 ,
@@ -383,7 +417,8 @@ func TestCreateServers(t *testing.T) {
383
417
},
384
418
},
385
419
{
386
- Path : "/redirect-implicit-port" ,
420
+ Path : "/redirect-implicit-port" ,
421
+ PathType : dataplane .PathTypePrefix ,
387
422
MatchRules : []dataplane.MatchRule {
388
423
{
389
424
MatchIdx : 0 ,
@@ -399,7 +434,8 @@ func TestCreateServers(t *testing.T) {
399
434
},
400
435
},
401
436
{
402
- Path : "/redirect-explicit-port" ,
437
+ Path : "/redirect-explicit-port" ,
438
+ PathType : dataplane .PathTypePrefix ,
403
439
MatchRules : []dataplane.MatchRule {
404
440
{
405
441
MatchIdx : 0 ,
@@ -416,7 +452,8 @@ func TestCreateServers(t *testing.T) {
416
452
},
417
453
},
418
454
{
419
- Path : "/invalid-filter" ,
455
+ Path : "/invalid-filter" ,
456
+ PathType : dataplane .PathTypePrefix ,
420
457
MatchRules : []dataplane.MatchRule {
421
458
{
422
459
MatchIdx : 0 ,
@@ -429,6 +466,30 @@ func TestCreateServers(t *testing.T) {
429
466
},
430
467
},
431
468
},
469
+ {
470
+ Path : "/exact" ,
471
+ PathType : dataplane .PathTypeExact ,
472
+ MatchRules : []dataplane.MatchRule {
473
+ {
474
+ MatchIdx : 0 ,
475
+ RuleIdx : 6 ,
476
+ Source : hr ,
477
+ BackendGroup : fooGroup ,
478
+ },
479
+ },
480
+ },
481
+ {
482
+ Path : "/test" ,
483
+ PathType : dataplane .PathTypeExact ,
484
+ MatchRules : []dataplane.MatchRule {
485
+ {
486
+ MatchIdx : 0 ,
487
+ RuleIdx : 7 ,
488
+ Source : hr ,
489
+ BackendGroup : fooGroup ,
490
+ },
491
+ },
492
+ },
432
493
}
433
494
434
495
httpServers := []dataplane.VirtualServer {
@@ -461,16 +522,22 @@ func TestCreateServers(t *testing.T) {
461
522
}
462
523
463
524
slashMatches := []httpMatch {
464
- {Method : v1beta1 .HTTPMethodPost , RedirectPath : "/_route0 " },
465
- {Method : v1beta1 .HTTPMethodPatch , RedirectPath : "/_route1 " },
466
- {Any : true , RedirectPath : "/_route2 " },
525
+ {Method : v1beta1 .HTTPMethodPost , RedirectPath : "/_prefix_route0 " },
526
+ {Method : v1beta1 .HTTPMethodPatch , RedirectPath : "/_prefix_route1 " },
527
+ {Any : true , RedirectPath : "/_prefix_route2 " },
467
528
}
468
529
testMatches := []httpMatch {
469
530
{
470
531
Method : v1beta1 .HTTPMethodGet ,
471
532
Headers : []string {"Version:V1" , "test:foo" , "my-header:my-value" },
472
533
QueryParams : []string {"GrEat=EXAMPLE" , "test=foo=bar" },
473
- RedirectPath : "/test_route0" ,
534
+ RedirectPath : "/test_prefix_route0" ,
535
+ },
536
+ }
537
+ exactMatches := []httpMatch {
538
+ {
539
+ Method : v1beta1 .HTTPMethodGet ,
540
+ RedirectPath : "/test_exact_route0" ,
474
541
},
475
542
}
476
543
@@ -482,17 +549,17 @@ func TestCreateServers(t *testing.T) {
482
549
483
550
return []http.Location {
484
551
{
485
- Path : "/_route0 " ,
552
+ Path : "/_prefix_route0 " ,
486
553
Internal : true ,
487
554
ProxyPass : "http://test_foo_80" ,
488
555
},
489
556
{
490
- Path : "/_route1 " ,
557
+ Path : "/_prefix_route1 " ,
491
558
Internal : true ,
492
559
ProxyPass : "http://test_foo_80" ,
493
560
},
494
561
{
495
- Path : "/_route2 " ,
562
+ Path : "/_prefix_route2 " ,
496
563
Internal : true ,
497
564
ProxyPass : "http://test_foo_80" ,
498
565
},
@@ -501,7 +568,7 @@ func TestCreateServers(t *testing.T) {
501
568
HTTPMatchVar : expectedMatchString (slashMatches ),
502
569
},
503
570
{
504
- Path : "/test_route0 " ,
571
+ Path : "/test_prefix_route0 " ,
505
572
Internal : true ,
506
573
ProxyPass : "http://$test__route1_rule1" ,
507
574
},
@@ -533,6 +600,21 @@ func TestCreateServers(t *testing.T) {
533
600
Code : http .StatusInternalServerError ,
534
601
},
535
602
},
603
+ {
604
+ Path : "/exact" ,
605
+ ProxyPass : "http://test_foo_80" ,
606
+ Exact : true ,
607
+ },
608
+ {
609
+ Path : "/test_exact_route0" ,
610
+ ProxyPass : "http://test_foo_80" ,
611
+ Internal : true ,
612
+ },
613
+ {
614
+ Path : "/test" ,
615
+ HTTPMatchVar : expectedMatchString (exactMatches ),
616
+ Exact : true ,
617
+ },
536
618
}
537
619
}
538
620
@@ -579,11 +661,13 @@ func TestCreateLocationsRootPath(t *testing.T) {
579
661
{
580
662
Path : & v1beta1.HTTPPathMatch {
581
663
Value : helpers .GetStringPointer ("/path-1" ),
664
+ Type : helpers .GetPointer (v1beta1 .PathMatchPathPrefix ),
582
665
},
583
666
},
584
667
{
585
668
Path : & v1beta1.HTTPPathMatch {
586
669
Value : helpers .GetStringPointer ("/path-2" ),
670
+ Type : helpers .GetPointer (v1beta1 .PathMatchPathPrefix ),
587
671
},
588
672
},
589
673
},
@@ -596,6 +680,7 @@ func TestCreateLocationsRootPath(t *testing.T) {
596
680
route .Spec .Rules [0 ].Matches = append (route .Spec .Rules [0 ].Matches , v1beta1.HTTPRouteMatch {
597
681
Path : & v1beta1.HTTPPathMatch {
598
682
Value : helpers .GetStringPointer ("/" ),
683
+ Type : helpers .GetPointer (v1beta1 .PathMatchPathPrefix ),
599
684
},
600
685
})
601
686
}
@@ -1089,10 +1174,25 @@ func TestCreateMatchLocation(t *testing.T) {
1089
1174
}
1090
1175
1091
1176
func TestCreatePathForMatch (t * testing.T ) {
1092
- expected := "/path_route1"
1177
+ g := NewGomegaWithT ( t )
1093
1178
1094
- result := createPathForMatch ("/path" , 1 )
1095
- if result != expected {
1096
- t .Errorf ("createPathForMatch() returned %q but expected %q" , result , expected )
1179
+ tests := []struct {
1180
+ expected string
1181
+ pathType dataplane.PathType
1182
+ panic bool
1183
+ }{
1184
+ {
1185
+ expected : "/path_prefix_route1" ,
1186
+ pathType : dataplane .PathTypePrefix ,
1187
+ },
1188
+ {
1189
+ expected : "/path_exact_route1" ,
1190
+ pathType : dataplane .PathTypeExact ,
1191
+ },
1192
+ }
1193
+
1194
+ for _ , tc := range tests {
1195
+ result := createPathForMatch ("/path" , tc .pathType , 1 )
1196
+ g .Expect (result ).To (Equal (tc .expected ))
1097
1197
}
1098
1198
}
0 commit comments