Skip to content

Commit baf5287

Browse files
committed
add e2e test
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
1 parent 9dbe1f4 commit baf5287

File tree

2 files changed

+266
-0
lines changed

2 files changed

+266
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
---
2+
apiVersion: gateway.networking.k8s.io/v1
3+
kind: Gateway
4+
metadata:
5+
name: btp-section
6+
namespace: gateway-conformance-infra
7+
spec:
8+
gatewayClassName: "{GATEWAY_CLASS_NAME}"
9+
listeners:
10+
- name: listener-1
11+
hostname: "listener1.merged.example.com"
12+
port: 80
13+
protocol: HTTP
14+
allowedRoutes:
15+
namespaces:
16+
from: Same
17+
- name: listener-2
18+
hostname: "listener2.merged.example.com"
19+
port: 80
20+
protocol: HTTP
21+
allowedRoutes:
22+
namespaces:
23+
from: Same
24+
---
25+
apiVersion: gateway.networking.k8s.io/v1
26+
kind: HTTPRoute
27+
metadata:
28+
name: btp-section
29+
namespace: gateway-conformance-infra
30+
spec:
31+
parentRefs:
32+
- name: btp-section
33+
sectionName: listener-1
34+
hostnames: ["listener1.merged.example.com"]
35+
rules:
36+
- name: rule-1
37+
matches:
38+
- path:
39+
value: "/foo"
40+
backendRefs:
41+
- name: infra-backend-v1
42+
port: 8080
43+
- name: rule-2
44+
matches:
45+
- path:
46+
value: "/bar"
47+
backendRefs:
48+
- name: infra-backend-v1
49+
port: 8080
50+
---
51+
apiVersion: gateway.networking.k8s.io/v1
52+
kind: HTTPRoute
53+
metadata:
54+
name: btp-non-section
55+
namespace: gateway-conformance-infra
56+
spec:
57+
parentRefs:
58+
- name: btp-section
59+
sectionName: listener-2
60+
hostnames: ["listener2.merged.example.com"]
61+
rules:
62+
- matches:
63+
- path:
64+
value: "/foo"
65+
backendRefs:
66+
- name: infra-backend-v1
67+
port: 8080
68+
---
69+
apiVersion: gateway.envoyproxy.io/v1alpha1
70+
kind: BackendTrafficPolicy
71+
metadata:
72+
name: btp-section-gateway
73+
namespace: gateway-conformance-infra
74+
spec:
75+
targetRefs:
76+
- group: gateway.networking.k8s.io
77+
kind: Gateway
78+
name: btp-section
79+
sectionName: listener-1
80+
responseOverride:
81+
- match:
82+
statusCodes:
83+
- type: Range
84+
range:
85+
start: 418
86+
end: 420
87+
response:
88+
statusCode: 500
89+
---
90+
apiVersion: gateway.envoyproxy.io/v1alpha1
91+
kind: BackendTrafficPolicy
92+
metadata:
93+
name: btp-section-route
94+
namespace: gateway-conformance-infra
95+
spec:
96+
targetRefs:
97+
- group: gateway.networking.k8s.io
98+
kind: HTTPRoute
99+
name: btp-section
100+
mergeType: StrategicMerge
101+
faultInjection:
102+
abort:
103+
httpStatus: 418
104+
---
105+
apiVersion: gateway.envoyproxy.io/v1alpha1
106+
kind: BackendTrafficPolicy
107+
metadata:
108+
name: btp-section-route-rule
109+
namespace: gateway-conformance-infra
110+
spec:
111+
targetRefs:
112+
- group: gateway.networking.k8s.io
113+
kind: HTTPRoute
114+
name: btp-section
115+
sectionName: rule-2
116+
faultInjection:
117+
abort:
118+
httpStatus: 419
119+
---
120+
apiVersion: gateway.envoyproxy.io/v1alpha1
121+
kind: BackendTrafficPolicy
122+
metadata:
123+
name: btp-non-section-route
124+
namespace: gateway-conformance-infra
125+
spec:
126+
targetRefs:
127+
- group: gateway.networking.k8s.io
128+
kind: HTTPRoute
129+
name: btp-non-section
130+
mergeType: StrategicMerge
131+
faultInjection:
132+
abort:
133+
httpStatus: 420
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// Copyright Envoy Gateway Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
// The full text of the Apache license is available in the LICENSE file at
4+
// the root of the repo.
5+
6+
//go:build e2e
7+
8+
package tests
9+
10+
import (
11+
"testing"
12+
13+
"k8s.io/apimachinery/pkg/types"
14+
"k8s.io/utils/ptr"
15+
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
16+
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
17+
"sigs.k8s.io/gateway-api/conformance/utils/http"
18+
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
19+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
20+
21+
"github.com/envoyproxy/gateway/internal/gatewayapi"
22+
"github.com/envoyproxy/gateway/internal/gatewayapi/resource"
23+
)
24+
25+
func init() {
26+
ConformanceTests = append(ConformanceTests, BackendTrafficPolicyMergedTest)
27+
}
28+
29+
var BackendTrafficPolicyMergedTest = suite.ConformanceTest{
30+
ShortName: "BackendTrafficPolicyMerged",
31+
Description: "Test section level policy attach and merged parent policy for BackendTrafficPolicy",
32+
Manifests: []string{"testdata/backendtrafficpolicy-section-merged.yaml"},
33+
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
34+
t.Run("BackendTrafficPolicyMerged", func(t *testing.T) {
35+
ns := "gateway-conformance-infra"
36+
37+
sectionRouteNN := types.NamespacedName{Name: "btp-section", Namespace: ns}
38+
nonsectionRouteNN := types.NamespacedName{Name: "btp-non-section", Namespace: ns}
39+
gwNN := types.NamespacedName{Name: "btp-section", Namespace: ns}
40+
41+
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t,
42+
suite.Client,
43+
suite.TimeoutConfig,
44+
suite.ControllerName,
45+
kubernetes.NewGatewayRef(gwNN),
46+
sectionRouteNN,
47+
nonsectionRouteNN,
48+
)
49+
50+
BackendTrafficPolicyMustBeAccepted(t,
51+
suite.Client,
52+
types.NamespacedName{Name: "btp-section-gateway", Namespace: ns},
53+
suite.ControllerName,
54+
gwapiv1a2.ParentReference{
55+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
56+
Kind: gatewayapi.KindPtr(resource.KindGateway),
57+
Namespace: gatewayapi.NamespacePtr(gwNN.Namespace),
58+
Name: gwapiv1.ObjectName(gwNN.Name),
59+
SectionName: ptr.To(gwapiv1.SectionName("listener-1")),
60+
},
61+
)
62+
63+
BackendTrafficPolicyMustBeAccepted(t,
64+
suite.Client,
65+
types.NamespacedName{Name: "btp-section-route", Namespace: ns},
66+
suite.ControllerName,
67+
gwapiv1a2.ParentReference{
68+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
69+
Kind: gatewayapi.KindPtr(resource.KindGateway),
70+
Namespace: gatewayapi.NamespacePtr(gwNN.Namespace),
71+
Name: gwapiv1.ObjectName(gwNN.Name),
72+
SectionName: ptr.To(gwapiv1.SectionName("listener-1")),
73+
},
74+
)
75+
76+
BackendTrafficPolicyMustBeAccepted(t,
77+
suite.Client,
78+
types.NamespacedName{Name: "btp-section-route-rule", Namespace: ns},
79+
suite.ControllerName,
80+
gwapiv1a2.ParentReference{
81+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
82+
Kind: gatewayapi.KindPtr(resource.KindGateway),
83+
Namespace: gatewayapi.NamespacePtr(gwNN.Namespace),
84+
Name: gwapiv1.ObjectName(gwNN.Name),
85+
SectionName: ptr.To(gwapiv1.SectionName("listener-1")),
86+
},
87+
)
88+
89+
BackendTrafficPolicyMustBeAccepted(t,
90+
suite.Client,
91+
types.NamespacedName{Name: "btp-non-section-route", Namespace: ns},
92+
suite.ControllerName,
93+
gwapiv1a2.ParentReference{
94+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
95+
Kind: gatewayapi.KindPtr(resource.KindGateway),
96+
Namespace: gatewayapi.NamespacePtr(gwNN.Namespace),
97+
Name: gwapiv1.ObjectName(gwNN.Name),
98+
SectionName: ptr.To(gwapiv1.SectionName("listener-2")),
99+
},
100+
)
101+
102+
// Test 1: HTTPRoute btp-section/rule-2 with section-level FaultInjection (419)
103+
// This rule has its own BTP without mergeType, so Gateway's ResponseOverride doesn't apply.
104+
// Expected: StatusCode 419 (FaultInjection abort)
105+
expectedResponse := http.ExpectedResponse{
106+
Namespace: ns,
107+
Request: http.Request{Host: "listener1.merged.example.com", Path: "/bar"},
108+
Response: http.Response{StatusCode: 419},
109+
}
110+
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
111+
112+
// Test 2: HTTPRoute btp-section/rule-1 with merged BTP (FaultInjection 418 + ResponseOverride)
113+
// Route-level FaultInjection (418) with mergeType merges with Gateway's ResponseOverride (418->500).
114+
// Expected: StatusCode 500 (ResponseOverride transforms 418 to 500)
115+
expectedResponse = http.ExpectedResponse{
116+
Namespace: ns,
117+
Request: http.Request{Host: "listener1.merged.example.com", Path: "/foo"},
118+
Response: http.Response{StatusCode: 500},
119+
}
120+
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
121+
122+
// Test 3: HTTPRoute btp-non-section on listener-2 with merged BTP (FaultInjection 420)
123+
// This route uses listener-2 which doesn't have Gateway ResponseOverride (listener-1 only).
124+
// Expected: StatusCode 420 (FaultInjection abort, no ResponseOverride applied)
125+
expectedResponse = http.ExpectedResponse{
126+
Namespace: ns,
127+
Request: http.Request{Host: "listener2.merged.example.com", Path: "/foo"},
128+
Response: http.Response{StatusCode: 420},
129+
}
130+
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
131+
})
132+
},
133+
}

0 commit comments

Comments
 (0)