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, HTTPRouteHeaderMatching)
31 }
32
33 var HTTPRouteHeaderMatching = suite.ConformanceTest{
34 ShortName: "HTTPRouteHeaderMatching",
35 Description: "A single HTTPRoute with header matching for different backends",
36 Features: []suite.SupportedFeature{
37 suite.SupportGateway,
38 suite.SupportHTTPRoute,
39 },
40 Manifests: []string{"tests/httproute-header-matching.yaml"},
41 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
42 ns := "gateway-conformance-infra"
43 routeNN := types.NamespacedName{Name: "header-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: "/", Headers: map[string]string{"Version": "one"}},
50 Backend: "infra-backend-v1",
51 Namespace: ns,
52 }, {
53 Request: http.Request{Path: "/", Headers: map[string]string{"Version": "two"}},
54 Backend: "infra-backend-v2",
55 Namespace: ns,
56 }, {
57 Request: http.Request{Path: "/", Headers: map[string]string{"Version": "two", "Color": "orange"}},
58 Backend: "infra-backend-v1",
59 Namespace: ns,
60 }, {
61 Request: http.Request{Path: "/", Headers: map[string]string{"Version": "two", "Color": "blue"}},
62 Backend: "infra-backend-v2",
63 Namespace: ns,
64 }, {
65 Request: http.Request{Path: "/", Headers: map[string]string{"Color": "orange"}},
66 Response: http.Response{StatusCode: 404},
67 }, {
68 Request: http.Request{Path: "/", Headers: map[string]string{"Some-Other-Header": "one"}},
69 Response: http.Response{StatusCode: 404},
70 }, {
71 Request: http.Request{Path: "/", Headers: map[string]string{"Color": "blue"}},
72 Backend: "infra-backend-v1",
73 Namespace: ns,
74 }, {
75 Request: http.Request{Path: "/", Headers: map[string]string{"Color": "green"}},
76 Backend: "infra-backend-v1",
77 Namespace: ns,
78 }, {
79 Request: http.Request{Path: "/", Headers: map[string]string{"Color": "red"}},
80 Backend: "infra-backend-v2",
81 Namespace: ns,
82 }, {
83 Request: http.Request{Path: "/", Headers: map[string]string{"Color": "yellow"}},
84 Backend: "infra-backend-v2",
85 Namespace: ns,
86 }, {
87 Request: http.Request{Path: "/", Headers: map[string]string{"Color": "purple"}},
88 Response: http.Response{StatusCode: 404},
89 }}
90
91 for i := range testCases {
92
93
94 tc := testCases[i]
95 t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
96 t.Parallel()
97 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc)
98 })
99 }
100 },
101 }
102
View as plain text