1
16
17 package tests
18
19 import (
20 "testing"
21
22 "k8s.io/apimachinery/pkg/types"
23
24 "sigs.k8s.io/gateway-api/conformance/utils/http"
25 "sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
26 "sigs.k8s.io/gateway-api/conformance/utils/suite"
27 )
28
29 func init() {
30 ConformanceTests = append(ConformanceTests, HTTPRouteMatching)
31 }
32
33 var HTTPRouteMatching = suite.ConformanceTest{
34 ShortName: "HTTPRouteMatching",
35 Description: "A single HTTPRoute with path and header matching for different backends",
36 Features: []suite.SupportedFeature{
37 suite.SupportGateway,
38 suite.SupportHTTPRoute,
39 },
40 Manifests: []string{"tests/httproute-matching.yaml"},
41 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
42 ns := "gateway-conformance-infra"
43 routeNN := types.NamespacedName{Name: "matching", Namespace: ns}
44 gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
45 gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
46 kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN)
47
48 testCases := []http.ExpectedResponse{{
49 Request: http.Request{Path: "/"},
50 Backend: "infra-backend-v1",
51 Namespace: ns,
52 }, {
53 Request: http.Request{Path: "/example"},
54 Backend: "infra-backend-v1",
55 Namespace: ns,
56 }, {
57 Request: http.Request{Path: "/", Headers: map[string]string{"Version": "one"}},
58 Backend: "infra-backend-v1",
59 Namespace: ns,
60 }, {
61 Request: http.Request{Path: "/v2"},
62 Backend: "infra-backend-v2",
63 Namespace: ns,
64 }, {
65 Request: http.Request{Path: "/v2/example"},
66 Backend: "infra-backend-v2",
67 Namespace: ns,
68 }, {
69 Request: http.Request{Path: "/", Headers: map[string]string{"Version": "two"}},
70 Backend: "infra-backend-v2",
71 Namespace: ns,
72 }, {
73 Request: http.Request{Path: "/v2/"},
74 Backend: "infra-backend-v2",
75 Namespace: ns,
76 }, {
77
78 Request: http.Request{Path: "/v2example"},
79 Backend: "infra-backend-v1",
80 Namespace: ns,
81 }, {
82 Request: http.Request{Path: "/foo/v2/example"},
83 Backend: "infra-backend-v1",
84 Namespace: ns,
85 }}
86
87 for i := range testCases {
88
89
90 tc := testCases[i]
91 t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
92 t.Parallel()
93 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc)
94 })
95 }
96 },
97 }
98
View as plain text