7
7
"testing"
8
8
9
9
. "github.com/onsi/gomega"
10
+ "github.com/onsi/gomega/format"
10
11
"k8s.io/apimachinery/pkg/types"
11
12
12
13
"github.com/nginx/nginx-gateway-fabric/internal/framework/helpers"
@@ -862,6 +863,66 @@ func TestCreateServers(t *testing.T) {
862
863
},
863
864
},
864
865
},
866
+ {
867
+ Path : "/mirror" ,
868
+ PathType : dataplane .PathTypePrefix ,
869
+ MatchRules : []dataplane.MatchRule {
870
+ {
871
+ Match : dataplane.Match {},
872
+ Filters : dataplane.HTTPFilters {
873
+ RequestMirrors : []* dataplane.HTTPRequestMirrorFilter {
874
+ {
875
+ Name : helpers .GetPointer ("mirror-filter" ),
876
+ Namespace : helpers .GetPointer ("test-ns" ),
877
+ Target : helpers .GetPointer (http .InternalMirrorRoutePathPrefix + "-my-backend" ),
878
+ },
879
+ },
880
+ },
881
+ BackendGroup : fooGroup ,
882
+ },
883
+ },
884
+ },
885
+ {
886
+ Path : http .InternalMirrorRoutePathPrefix + "-my-backend" ,
887
+ PathType : dataplane .PathTypeExact ,
888
+ MatchRules : []dataplane.MatchRule {
889
+ {
890
+ Match : dataplane.Match {},
891
+ BackendGroup : fooGroup ,
892
+ },
893
+ },
894
+ },
895
+ {
896
+ Path : "/grpc/mirror" ,
897
+ PathType : dataplane .PathTypeExact ,
898
+ MatchRules : []dataplane.MatchRule {
899
+ {
900
+ Match : dataplane.Match {},
901
+ Filters : dataplane.HTTPFilters {
902
+ RequestMirrors : []* dataplane.HTTPRequestMirrorFilter {
903
+ {
904
+ Name : helpers .GetPointer ("grpc-mirror-filter" ),
905
+ Namespace : helpers .GetPointer ("test-ns" ),
906
+ Target : helpers .GetPointer (http .InternalMirrorRoutePathPrefix + "-my-grpc-backend" ),
907
+ },
908
+ },
909
+ },
910
+ BackendGroup : fooGroup ,
911
+ },
912
+ },
913
+ GRPC : true ,
914
+ },
915
+ {
916
+ Path : http .InternalMirrorRoutePathPrefix + "-my-grpc-backend" ,
917
+ PathType : dataplane .PathTypeExact ,
918
+ MatchRules : []dataplane.MatchRule {
919
+ {
920
+ Match : dataplane.Match {},
921
+ BackendGroup : fooGroup ,
922
+ },
923
+ },
924
+ GRPC : true ,
925
+ },
865
926
{
866
927
Path : "/invalid-filter" ,
867
928
PathType : dataplane .PathTypePrefix ,
@@ -1093,25 +1154,25 @@ func TestCreateServers(t *testing.T) {
1093
1154
RedirectPath : "/_ngf-internal-rule8-route0" ,
1094
1155
},
1095
1156
},
1096
- "1_10 " : {
1157
+ "1_14 " : {
1097
1158
{
1098
1159
Headers : []string {"filter:Exact:this" },
1099
- RedirectPath : "/_ngf-internal-rule10 -route0" ,
1160
+ RedirectPath : "/_ngf-internal-rule14 -route0" ,
1100
1161
},
1101
1162
},
1102
- "1_12 " : {
1163
+ "1_16 " : {
1103
1164
{
1104
1165
Method : "GET" ,
1105
- RedirectPath : "/_ngf-internal-rule12 -route0" ,
1166
+ RedirectPath : "/_ngf-internal-rule16 -route0" ,
1106
1167
Headers : nil ,
1107
1168
QueryParams : nil ,
1108
1169
Any : false ,
1109
1170
},
1110
1171
},
1111
- "1_17 " : {
1172
+ "1_21 " : {
1112
1173
{
1113
1174
Method : "GET" ,
1114
- RedirectPath : "/_ngf-internal-rule17 -route0" ,
1175
+ RedirectPath : "/_ngf-internal-rule21 -route0" ,
1115
1176
},
1116
1177
},
1117
1178
}
@@ -1342,6 +1403,47 @@ func TestCreateServers(t *testing.T) {
1342
1403
Type : http .InternalLocationType ,
1343
1404
Includes : internalIncludes ,
1344
1405
},
1406
+ {
1407
+ Path : "/mirror/" ,
1408
+ ProxyPass : "http://test_foo_80$request_uri" ,
1409
+ ProxySetHeaders : httpBaseHeaders ,
1410
+ MirrorPaths : []string {"/_ngf-internal-mirror-my-backend" },
1411
+ Type : http .ExternalLocationType ,
1412
+ Includes : externalIncludes ,
1413
+ },
1414
+ {
1415
+ Path : "= /mirror" ,
1416
+ ProxyPass : "http://test_foo_80$request_uri" ,
1417
+ ProxySetHeaders : httpBaseHeaders ,
1418
+ MirrorPaths : []string {"/_ngf-internal-mirror-my-backend" },
1419
+ Type : http .ExternalLocationType ,
1420
+ Includes : externalIncludes ,
1421
+ },
1422
+ {
1423
+ Path : "= /_ngf-internal-mirror-my-backend" ,
1424
+ ProxyPass : "http://test_foo_80$request_uri" ,
1425
+ ProxySetHeaders : httpBaseHeaders ,
1426
+ Type : http .InternalLocationType ,
1427
+ Includes : externalIncludes ,
1428
+ },
1429
+ {
1430
+ Path : "= /grpc/mirror" ,
1431
+ GRPC : true ,
1432
+ ProxyPass : "grpc://test_foo_80" ,
1433
+ ProxySetHeaders : grpcBaseHeaders ,
1434
+ MirrorPaths : []string {"/_ngf-internal-mirror-my-grpc-backend" },
1435
+ Type : http .ExternalLocationType ,
1436
+ Includes : externalIncludes ,
1437
+ },
1438
+ {
1439
+ Path : "= /_ngf-internal-mirror-my-grpc-backend" ,
1440
+ GRPC : true ,
1441
+ ProxyPass : "grpc://test_foo_80" ,
1442
+ Rewrites : []string {"^ $request_uri break" },
1443
+ ProxySetHeaders : grpcBaseHeaders ,
1444
+ Type : http .InternalLocationType ,
1445
+ Includes : externalIncludes ,
1446
+ },
1345
1447
{
1346
1448
Path : "/invalid-filter/" ,
1347
1449
Return : & http.Return {
@@ -1360,18 +1462,18 @@ func TestCreateServers(t *testing.T) {
1360
1462
},
1361
1463
{
1362
1464
Path : "/invalid-filter-with-headers/" ,
1363
- HTTPMatchKey : ssl + "1_10 " ,
1465
+ HTTPMatchKey : ssl + "1_14 " ,
1364
1466
Type : http .RedirectLocationType ,
1365
1467
Includes : externalIncludes ,
1366
1468
},
1367
1469
{
1368
1470
Path : "= /invalid-filter-with-headers" ,
1369
- HTTPMatchKey : ssl + "1_10 " ,
1471
+ HTTPMatchKey : ssl + "1_14 " ,
1370
1472
Type : http .RedirectLocationType ,
1371
1473
Includes : externalIncludes ,
1372
1474
},
1373
1475
{
1374
- Path : "/_ngf-internal-rule10 -route0" ,
1476
+ Path : "/_ngf-internal-rule14 -route0" ,
1375
1477
Return : & http.Return {
1376
1478
Code : http .StatusInternalServerError ,
1377
1479
},
@@ -1387,12 +1489,12 @@ func TestCreateServers(t *testing.T) {
1387
1489
},
1388
1490
{
1389
1491
Path : "= /test" ,
1390
- HTTPMatchKey : ssl + "1_12 " ,
1492
+ HTTPMatchKey : ssl + "1_16 " ,
1391
1493
Type : http .RedirectLocationType ,
1392
1494
Includes : externalIncludes ,
1393
1495
},
1394
1496
{
1395
- Path : "/_ngf-internal-rule12 -route0" ,
1497
+ Path : "/_ngf-internal-rule16 -route0" ,
1396
1498
ProxyPass : "http://test_foo_80$request_uri" ,
1397
1499
ProxySetHeaders : httpBaseHeaders ,
1398
1500
Type : http .InternalLocationType ,
@@ -1471,15 +1573,14 @@ func TestCreateServers(t *testing.T) {
1471
1573
},
1472
1574
{
1473
1575
Path : "= /include-header-match" ,
1474
- HTTPMatchKey : ssl + "1_17 " ,
1576
+ HTTPMatchKey : ssl + "1_21 " ,
1475
1577
Type : http .RedirectLocationType ,
1476
1578
Includes : externalIncludes ,
1477
1579
},
1478
1580
{
1479
- Path : "/_ngf-internal-rule17 -route0" ,
1581
+ Path : "/_ngf-internal-rule21 -route0" ,
1480
1582
ProxyPass : "http://test_foo_80$request_uri" ,
1481
1583
ProxySetHeaders : httpBaseHeaders ,
1482
- Rewrites : []string {"^ $request_uri break" },
1483
1584
Type : http .InternalLocationType ,
1484
1585
Includes : internalIncludes ,
1485
1586
},
@@ -1572,6 +1673,7 @@ func TestCreateServers(t *testing.T) {
1572
1673
1573
1674
result , httpMatchPair := createServers (conf , fakeGenerator , keepAliveCheck )
1574
1675
1676
+ format .MaxLength = 10000
1575
1677
g .Expect (httpMatchPair ).To (Equal (allExpMatchPair ))
1576
1678
g .Expect (helpers .Diff (expectedServers , result )).To (BeEmpty ())
1577
1679
}
0 commit comments