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, HTTPExactPathMatching)
31 }
32
33 var HTTPExactPathMatching = suite.ConformanceTest{
34 ShortName: "HTTPExactPathMatching",
35 Description: "A single HTTPRoute with exact path matching for different backends",
36 Features: []suite.SupportedFeature{
37 suite.SupportGateway,
38 suite.SupportHTTPRoute,
39 },
40 Manifests: []string{"tests/httproute-exact-path-matching.yaml"},
41 Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
42 ns := "gateway-conformance-infra"
43 routeNN := types.NamespacedName{Name: "exact-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 {
50 Request: http.Request{Path: "/one"},
51 Backend: "infra-backend-v1",
52 Namespace: ns,
53 }, {
54 Request: http.Request{Path: "/two"},
55 Backend: "infra-backend-v2",
56 Namespace: ns,
57 }, {
58 Request: http.Request{Path: "/"},
59 Response: http.Response{StatusCode: 404},
60 }, {
61 Request: http.Request{Path: "/one/example"},
62 Response: http.Response{StatusCode: 404},
63 }, {
64 Request: http.Request{Path: "/two/"},
65 Response: http.Response{StatusCode: 404},
66 }, {
67 Request: http.Request{Path: "/Two"},
68 Response: http.Response{StatusCode: 404},
69 },
70 }
71
72 for i := range testCases {
73
74
75 tc := testCases[i]
76 t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
77 t.Parallel()
78 http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc)
79 })
80 }
81 },
82 }
83
View as plain text