Skip to content

Commit 1e14dd6

Browse files
add mesh conformance tests structure and a first test (#3729)
* add mesh confomance tests structure and first test * move mesh tests to mesh folder
1 parent 40be951 commit 1e14dd6

16 files changed

+317
-19
lines changed

conformance/tests/main.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ limitations under the License.
1616

1717
package tests
1818

19-
import "sigs.k8s.io/gateway-api/conformance/utils/suite"
19+
import (
20+
"slices"
2021

21-
var ConformanceTests []suite.ConformanceTest
22+
meshtests "sigs.k8s.io/gateway-api/conformance/tests/mesh"
23+
)
24+
25+
var ConformanceTests = slices.Clone(meshtests.MeshConformanceTests)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
Copyright 2025 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, MeshHTTPRouteRewritePath)
30+
}
31+
32+
var MeshHTTPRouteRewritePath = suite.ConformanceTest{
33+
ShortName: "MeshHTTPRouteRewritePath",
34+
Description: "An HTTPRoute with path rewrite filter",
35+
Features: []features.FeatureName{
36+
features.SupportMesh,
37+
features.SupportMeshHTTPRouteRewritePath,
38+
features.SupportHTTPRoute,
39+
},
40+
Manifests: []string{"tests/mesh/httproute-rewrite-path.yaml"},
41+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
42+
ns := "gateway-conformance-mesh"
43+
client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1)
44+
cases := []http.ExpectedResponse{
45+
{
46+
Request: http.Request{
47+
Path: "/prefix/one/two",
48+
Host: "echo",
49+
},
50+
ExpectedRequest: &http.ExpectedRequest{
51+
Request: http.Request{
52+
Path: "/one/two",
53+
},
54+
},
55+
Backend: "echo-v1",
56+
Namespace: ns,
57+
},
58+
{
59+
Request: http.Request{
60+
Path: "/strip-prefix/three",
61+
Host: "echo",
62+
},
63+
ExpectedRequest: &http.ExpectedRequest{
64+
Request: http.Request{
65+
Path: "/three",
66+
},
67+
},
68+
Backend: "echo-v1",
69+
Namespace: ns,
70+
},
71+
{
72+
Request: http.Request{
73+
Path: "/strip-prefix",
74+
Host: "echo",
75+
},
76+
ExpectedRequest: &http.ExpectedRequest{
77+
Request: http.Request{
78+
Path: "/",
79+
},
80+
},
81+
Backend: "echo-v1",
82+
Namespace: ns,
83+
},
84+
{
85+
Request: http.Request{
86+
Path: "/full/one/two",
87+
Host: "echo",
88+
},
89+
ExpectedRequest: &http.ExpectedRequest{
90+
Request: http.Request{
91+
Path: "/one",
92+
},
93+
},
94+
Backend: "echo-v1",
95+
Namespace: ns,
96+
},
97+
{
98+
Request: http.Request{
99+
Host: "echo",
100+
Path: "/full/rewrite-path-and-modify-headers/test",
101+
Headers: map[string]string{
102+
"X-Header-Remove": "remove-val",
103+
"X-Header-Add-Append": "append-val-1",
104+
"X-Header-Set": "set-val",
105+
},
106+
},
107+
ExpectedRequest: &http.ExpectedRequest{
108+
Request: http.Request{
109+
Path: "/test",
110+
Headers: map[string]string{
111+
"X-Header-Add": "header-val-1",
112+
"X-Header-Add-Append": "append-val-1,header-val-2",
113+
"X-Header-Set": "set-overwrites-values",
114+
},
115+
},
116+
AbsentHeaders: []string{"X-Header-Remove"},
117+
},
118+
Backend: "echo-v1",
119+
Namespace: ns,
120+
},
121+
{
122+
Request: http.Request{
123+
Host: "echo",
124+
Path: "/prefix/rewrite-path-and-modify-headers/one",
125+
Headers: map[string]string{
126+
"X-Header-Remove": "remove-val",
127+
"X-Header-Add-Append": "append-val-1",
128+
"X-Header-Set": "set-val",
129+
},
130+
},
131+
ExpectedRequest: &http.ExpectedRequest{
132+
Request: http.Request{
133+
Path: "/prefix/one",
134+
Headers: map[string]string{
135+
"X-Header-Add": "header-val-1",
136+
"X-Header-Add-Append": "append-val-1,header-val-2",
137+
"X-Header-Set": "set-overwrites-values",
138+
},
139+
},
140+
AbsentHeaders: []string{"X-Header-Remove"},
141+
},
142+
Backend: "echo-v1",
143+
Namespace: ns,
144+
},
145+
}
146+
for i := range cases {
147+
// Declare tc here to avoid loop variable
148+
// reuse issues across parallel tests.
149+
tc := cases[i]
150+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
151+
client.MakeRequestAndExpectEventuallyConsistentResponse(t, tc, s.TimeoutConfig)
152+
})
153+
}
154+
},
155+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: mesh-rewrite-path
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: /prefix/one
17+
filters:
18+
- type: URLRewrite
19+
urlRewrite:
20+
path:
21+
type: ReplacePrefixMatch
22+
replacePrefixMatch: /one
23+
backendRefs:
24+
- name: echo-v1
25+
port: 80
26+
- matches:
27+
- path:
28+
type: PathPrefix
29+
value: /strip-prefix
30+
filters:
31+
- type: URLRewrite
32+
urlRewrite:
33+
path:
34+
type: ReplacePrefixMatch
35+
replacePrefixMatch: /
36+
backendRefs:
37+
- name: echo-v1
38+
port: 80
39+
- matches:
40+
- path:
41+
type: PathPrefix
42+
value: /full/one
43+
filters:
44+
- type: URLRewrite
45+
urlRewrite:
46+
path:
47+
type: ReplaceFullPath
48+
replaceFullPath: /one
49+
backendRefs:
50+
- name: echo-v1
51+
port: 80
52+
- matches:
53+
- path:
54+
type: PathPrefix
55+
value: /full/rewrite-path-and-modify-headers
56+
filters:
57+
- type: URLRewrite
58+
urlRewrite:
59+
path:
60+
type: ReplaceFullPath
61+
replaceFullPath: /test
62+
- type: RequestHeaderModifier
63+
requestHeaderModifier:
64+
set:
65+
- name: X-Header-Set
66+
value: set-overwrites-values
67+
add:
68+
- name: X-Header-Add
69+
value: header-val-1
70+
- name: X-Header-Add-Append
71+
value: header-val-2
72+
remove:
73+
- X-Header-Remove
74+
backendRefs:
75+
- name: echo-v1
76+
port: 80
77+
- matches:
78+
- path:
79+
type: PathPrefix
80+
value: /prefix/rewrite-path-and-modify-headers
81+
filters:
82+
- type: URLRewrite
83+
urlRewrite:
84+
path:
85+
type: ReplacePrefixMatch
86+
replacePrefixMatch: /prefix
87+
- type: RequestHeaderModifier
88+
requestHeaderModifier:
89+
set:
90+
- name: X-Header-Set
91+
value: set-overwrites-values
92+
add:
93+
- name: X-Header-Add
94+
value: header-val-1
95+
- name: X-Header-Add-Append
96+
value: header-val-2
97+
remove:
98+
- X-Header-Remove
99+
backendRefs:
100+
- name: echo-v1
101+
port: 80

conformance/tests/mesh/main.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright 2025 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 "sigs.k8s.io/gateway-api/conformance/utils/suite"
20+
21+
var MeshConformanceTests []suite.ConformanceTest

conformance/tests/mesh-basic.go renamed to conformance/tests/mesh/mesh-basic.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package tests
17+
package meshtests
1818

1919
import (
2020
"testing"
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
func init() {
29-
ConformanceTests = append(ConformanceTests, MeshBasic)
29+
MeshConformanceTests = append(MeshConformanceTests, MeshBasic)
3030
}
3131

3232
var MeshBasic = suite.ConformanceTest{

conformance/tests/mesh-consumer-route.go renamed to conformance/tests/mesh/mesh-consumer-route.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package tests
17+
package meshtests
1818

1919
import (
2020
"testing"
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
func init() {
29-
ConformanceTests = append(ConformanceTests, MeshConsumerRoute)
29+
MeshConformanceTests = append(MeshConformanceTests, MeshConsumerRoute)
3030
}
3131

3232
var MeshConsumerRoute = suite.ConformanceTest{
@@ -38,7 +38,7 @@ var MeshConsumerRoute = suite.ConformanceTest{
3838
features.SupportHTTPRoute,
3939
features.SupportHTTPRouteResponseHeaderModification,
4040
},
41-
Manifests: []string{"tests/mesh-consumer-route.yaml"},
41+
Manifests: []string{"tests/mesh/mesh-consumer-route.yaml"},
4242
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
4343
consumerClient := echo.ConnectToAppInNamespace(t, s, echo.MeshAppEchoV1, "gateway-conformance-mesh-consumer")
4444
consumerCases := []http.ExpectedResponse{

conformance/tests/mesh-frontend-hostname.go renamed to conformance/tests/mesh/mesh-frontend-hostname.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package tests
17+
package meshtests
1818

1919
import (
2020
"testing"
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
func init() {
29-
ConformanceTests = append(ConformanceTests, MeshFrontendHostname)
29+
MeshConformanceTests = append(MeshConformanceTests, MeshFrontendHostname)
3030
}
3131

3232
var MeshFrontendHostname = suite.ConformanceTest{
@@ -38,7 +38,7 @@ var MeshFrontendHostname = suite.ConformanceTest{
3838
features.SupportHTTPRoute,
3939
features.SupportHTTPRouteResponseHeaderModification,
4040
},
41-
Manifests: []string{"tests/mesh-frontend.yaml"},
41+
Manifests: []string{"tests/mesh/mesh-frontend.yaml"},
4242
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
4343
client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1)
4444
cases := []http.ExpectedResponse{

conformance/tests/mesh-frontend.go renamed to conformance/tests/mesh/mesh-frontend.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package tests
17+
package meshtests
1818

1919
import (
2020
"testing"
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
func init() {
29-
ConformanceTests = append(ConformanceTests, MeshFrontend)
29+
MeshConformanceTests = append(MeshConformanceTests, MeshFrontend)
3030
}
3131

3232
var MeshFrontend = suite.ConformanceTest{
@@ -37,7 +37,7 @@ var MeshFrontend = suite.ConformanceTest{
3737
features.SupportHTTPRoute,
3838
features.SupportHTTPRouteResponseHeaderModification,
3939
},
40-
Manifests: []string{"tests/mesh-frontend.yaml"},
40+
Manifests: []string{"tests/mesh/mesh-frontend.yaml"},
4141
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
4242
client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1)
4343
v2 := echo.ConnectToApp(t, s, echo.MeshAppEchoV2)

0 commit comments

Comments
 (0)