Skip to content

Commit 77baa43

Browse files
add httproute matching conformance (#3831)
1 parent a879542 commit 77baa43

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package meshtests
18+
19+
import (
20+
"testing"
21+
22+
"sigs.k8s.io/gateway-api/conformance/utils/echo"
23+
"sigs.k8s.io/gateway-api/conformance/utils/http"
24+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
25+
"sigs.k8s.io/gateway-api/pkg/features"
26+
)
27+
28+
func init() {
29+
MeshConformanceTests = append(MeshConformanceTests, MeshHTTPRouteMatching)
30+
}
31+
32+
var MeshHTTPRouteMatching = suite.ConformanceTest{
33+
ShortName: "MeshHTTPRouteMatching",
34+
Description: "A single HTTPRoute with path and header matching for different backends",
35+
Features: []features.FeatureName{
36+
features.SupportMesh,
37+
features.SupportHTTPRoute,
38+
},
39+
Manifests: []string{"tests/mesh/httproute-matching.yaml"},
40+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
41+
ns := "gateway-conformance-mesh"
42+
client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1)
43+
44+
testCases := []http.ExpectedResponse{{
45+
Request: http.Request{Path: "/"},
46+
Backend: "echo-v1",
47+
Namespace: ns,
48+
}, {
49+
Request: http.Request{Path: "/example"},
50+
Backend: "echo-v1",
51+
Namespace: ns,
52+
}, {
53+
Request: http.Request{Path: "/", Headers: map[string]string{"Version": "one"}},
54+
Backend: "echo-v1",
55+
Namespace: ns,
56+
}, {
57+
Request: http.Request{Path: "/v2"},
58+
Backend: "echo-v2",
59+
Namespace: ns,
60+
}, {
61+
Request: http.Request{Path: "/v2/example"},
62+
Backend: "echo-v2",
63+
Namespace: ns,
64+
}, {
65+
Request: http.Request{Path: "/", Headers: map[string]string{"Version": "two"}},
66+
Backend: "echo-v2",
67+
Namespace: ns,
68+
}, {
69+
Request: http.Request{Path: "/v2/"},
70+
Backend: "echo-v2",
71+
Namespace: ns,
72+
}, {
73+
// Not a path segment prefix so should not match /v2.
74+
Request: http.Request{Path: "/v2example"},
75+
Backend: "echo-v1",
76+
Namespace: ns,
77+
}, {
78+
Request: http.Request{Path: "/foo/v2/example"},
79+
Backend: "echo-v1",
80+
Namespace: ns,
81+
}}
82+
83+
for i := range testCases {
84+
// Declare tc here to avoid loop variable
85+
// reuse issues across parallel tests.
86+
tc := testCases[i]
87+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
88+
t.Parallel()
89+
client.MakeRequestAndExpectEventuallyConsistentResponse(t, tc, s.TimeoutConfig)
90+
})
91+
}
92+
},
93+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: mesh-matching
5+
namespace: gateway-conformance-mesh
6+
spec:
7+
parentRefs:
8+
- group: ""
9+
kind: Service
10+
name: echo
11+
port: 80
12+
rules:
13+
- matches:
14+
- path:
15+
type: PathPrefix
16+
value: /
17+
- headers:
18+
- name: version
19+
value: one
20+
backendRefs:
21+
- name: echo-v1
22+
port: 8080
23+
- matches:
24+
- path:
25+
type: PathPrefix
26+
value: /v2
27+
- headers:
28+
- name: version
29+
value: two
30+
backendRefs:
31+
- name: echo-v2
32+
port: 8080

0 commit comments

Comments
 (0)