Skip to content

Commit 524b9fe

Browse files
hdurand0710Gopher Bot
authored andcommitted
TEST/MEDIUM: add tests for Listener isolation feature (without hostname intersection)
1 parent 8404224 commit 524b9fe

33 files changed

Lines changed: 859 additions & 0 deletions

File tree

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//
2+
// Copyright 2025 HAProxy Technologies LLC
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+
package httprouteisolation
17+
18+
import (
19+
"path"
20+
"testing"
21+
22+
"github.com/haproxytech/haproxy-unified-gateway/test/integration/utils"
23+
"github.com/stretchr/testify/suite"
24+
)
25+
26+
// Adding HTTPRouteIsolationTestSuite, just to be able to debug directly
27+
type HTTPRouteIsolationTestSuite struct {
28+
HTTPRouteIsolationSuite
29+
}
30+
31+
func TestHTTPRouteIsolationTestSuite(t *testing.T) {
32+
suite.Run(t, new(HTTPRouteIsolationTestSuite))
33+
}
34+
35+
func (s *HTTPRouteIsolationTestSuite) Test_HTTPRoute_ListenerIsolation_1_route_attaches_to_empty_hostname() {
36+
fixtureDirPath := utils.GetCRDFixturePath()
37+
fixtureDir := "listener-isolation"
38+
39+
fixturePath := path.Join(fixtureDirPath, fixtureDir, "1-route-attaches-to-empty-hostname")
40+
s.CreateFixtures(fixturePath, nil)
41+
mapFilePath := "hug_http_8080"
42+
defer s.CleanupFixturesCheckMapFiles(fixturePath, nil, []string{mapFilePath})
43+
44+
// Expected Conditions
45+
expectationsPath := path.Join(fixturePath, "expectations")
46+
expectedCondPath := path.Join(expectationsPath, "route-conditions.yaml")
47+
expectedConditions := s.YamlToRouteConditions(expectedCondPath)
48+
49+
httpRouteName := "route-attaches-to-empty-hostname"
50+
s.expectConditionsUpdated(s.Test().Ctx, s.Test().Namespace, httpRouteName, expectedConditions)
51+
52+
// Check Maps
53+
expectedMapsPath := path.Join(expectationsPath, "maps")
54+
s.ExpectMapContents(mapFilePath, expectedMapsPath)
55+
}
56+
57+
func (s *HTTPRouteIsolationTestSuite) Test_HTTPRoute_ListenerIsolation_2_route_attaches_to_wildcard_example_com() {
58+
fixtureDirPath := utils.GetCRDFixturePath()
59+
fixtureDir := "listener-isolation"
60+
61+
fixturePath := path.Join(fixtureDirPath, fixtureDir, "2-route-attaches-to-wildcard-example-com")
62+
s.CreateFixtures(fixturePath, nil)
63+
mapFilePath := "hug_http_8080"
64+
defer s.CleanupFixturesCheckMapFiles(fixturePath, nil, []string{mapFilePath})
65+
66+
// Expected Conditions
67+
expectationsPath := path.Join(fixturePath, "expectations")
68+
expectedCondPath := path.Join(expectationsPath, "route-conditions.yaml")
69+
expectedConditions := s.YamlToRouteConditions(expectedCondPath)
70+
71+
httpRouteName := "route-attaches-to-wildcard-example-com"
72+
s.expectConditionsUpdated(s.Test().Ctx, s.Test().Namespace, httpRouteName, expectedConditions)
73+
74+
// Check Maps
75+
expectedMapsPath := path.Join(expectationsPath, "maps")
76+
s.ExpectMapContents(mapFilePath, expectedMapsPath)
77+
}
78+
79+
func (s *HTTPRouteIsolationTestSuite) Test_HTTPRoute_ListenerIsolation_3_route_attaches_to_wildcard_foo_example_com() {
80+
fixtureDirPath := utils.GetCRDFixturePath()
81+
fixtureDir := "listener-isolation"
82+
83+
fixturePath := path.Join(fixtureDirPath, fixtureDir, "3-route-attaches-to-wildcard-foo-example-com")
84+
s.CreateFixtures(fixturePath, nil)
85+
mapFilePath := "hug_http_8080"
86+
defer s.CleanupFixturesCheckMapFiles(fixturePath, nil, []string{mapFilePath})
87+
88+
// Expected Conditions
89+
expectationsPath := path.Join(fixturePath, "expectations")
90+
expectedCondPath := path.Join(expectationsPath, "route-conditions.yaml")
91+
expectedConditions := s.YamlToRouteConditions(expectedCondPath)
92+
93+
httpRouteName := "route-attaches-to-wildcard-foo-example-com"
94+
s.expectConditionsUpdated(s.Test().Ctx, s.Test().Namespace, httpRouteName, expectedConditions)
95+
96+
// Check Maps
97+
expectedMapsPath := path.Join(expectationsPath, "maps")
98+
s.ExpectMapContents(mapFilePath, expectedMapsPath)
99+
}
100+
101+
func (s *HTTPRouteIsolationTestSuite) Test_HTTPRoute_ListenerIsolation_4_route_attaches_to_abc_foo_example_com() {
102+
fixtureDirPath := utils.GetCRDFixturePath()
103+
fixtureDir := "listener-isolation"
104+
105+
fixturePath := path.Join(fixtureDirPath, fixtureDir, "4-route-attaches-to-abc-foo-example-com")
106+
s.CreateFixtures(fixturePath, nil)
107+
mapFilePath := "hug_http_8080"
108+
defer s.CleanupFixturesCheckMapFiles(fixturePath, nil, []string{mapFilePath})
109+
110+
// Expected Conditions
111+
expectationsPath := path.Join(fixturePath, "expectations")
112+
expectedCondPath := path.Join(expectationsPath, "route-conditions.yaml")
113+
expectedConditions := s.YamlToRouteConditions(expectedCondPath)
114+
115+
httpRouteName := "route-attaches-to-abc-foo-example-com"
116+
s.expectConditionsUpdated(s.Test().Ctx, s.Test().Namespace, httpRouteName, expectedConditions)
117+
118+
// Check Maps
119+
expectedMapsPath := path.Join(expectationsPath, "maps")
120+
s.ExpectMapContents(mapFilePath, expectedMapsPath)
121+
}
122+
123+
func (s *HTTPRouteIsolationTestSuite) Test_HTTPRoute_ListenerIsolation_5_all() {
124+
fixtureDirPath := utils.GetCRDFixturePath()
125+
fixtureDir := "listener-isolation"
126+
127+
fixturePath := path.Join(fixtureDirPath, fixtureDir, "5-all")
128+
s.CreateFixtures(fixturePath, nil)
129+
mapFilePath := "hug_http_8080"
130+
defer s.CleanupFixturesCheckMapFiles(fixturePath, nil, []string{mapFilePath})
131+
132+
// Check Maps
133+
expectationsPath := path.Join(fixturePath, "expectations")
134+
expectedMapsPath := path.Join(expectationsPath, "maps")
135+
s.ExpectMapContents(mapFilePath, expectedMapsPath)
136+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/empty-hostname hug_e2e-tests-httproute-listener-isolation_http-echo_80__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
parents:
2+
- conditions:
3+
- message: Route Accepted
4+
observedGeneration: 1
5+
reason: Accepted
6+
status: "True"
7+
type: Accepted
8+
- message: References resolved
9+
observedGeneration: 1
10+
reason: ResolvedRefs
11+
status: "True"
12+
type: ResolvedRefs
13+
controllerName: gate.haproxy.org/hug
14+
parentRef:
15+
group: gateway.networking.k8s.io
16+
kind: Gateway
17+
name: gateway
18+
sectionName: empty-hostname
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: Gateway
3+
metadata:
4+
name: gateway
5+
spec:
6+
gatewayClassName: haproxy
7+
listeners:
8+
- name: empty-hostname
9+
port: 8080
10+
protocol: HTTP
11+
allowedRoutes:
12+
kinds:
13+
- group: gateway.networking.k8s.io
14+
kind: HTTPRoute
15+
- name: wildcard-example-com
16+
protocol: HTTP
17+
port: 8080
18+
allowedRoutes:
19+
kinds:
20+
- group: gateway.networking.k8s.io
21+
kind: HTTPRoute
22+
hostname: "*.example.com"
23+
- name: wildcard-foo-example-com
24+
protocol: HTTP
25+
port: 8080
26+
allowedRoutes:
27+
kinds:
28+
- group: gateway.networking.k8s.io
29+
kind: HTTPRoute
30+
hostname: "*.foo.example.com"
31+
- name: abc-foo-example-com
32+
protocol: HTTP
33+
port: 8080
34+
allowedRoutes:
35+
kinds:
36+
- group: gateway.networking.k8s.io
37+
kind: HTTPRoute
38+
hostname: "abc.foo.example.com"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: GatewayClass
3+
metadata:
4+
name: haproxy
5+
spec:
6+
controllerName: gate.haproxy.org/hug
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
kind: Deployment
2+
apiVersion: apps/v1
3+
metadata:
4+
name: http-echo
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: http-echo
10+
template:
11+
metadata:
12+
labels:
13+
app: http-echo
14+
spec:
15+
containers:
16+
- name: http-echo
17+
image: "haproxytech/http-echo:latest"
18+
imagePullPolicy: IfNotPresent
19+
ports:
20+
- name: http
21+
containerPort: 8888
22+
protocol: TCP
23+
- name: https
24+
containerPort: 8443
25+
protocol: TCP
26+
---
27+
kind: Service
28+
apiVersion: v1
29+
metadata:
30+
name: http-echo
31+
spec:
32+
ports:
33+
- name: http
34+
protocol: TCP
35+
port: 80
36+
targetPort: http
37+
- name: https
38+
protocol: TCP
39+
port: 443
40+
targetPort: https
41+
selector:
42+
app: http-echo
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: route-attaches-to-empty-hostname
5+
spec:
6+
parentRefs:
7+
- name: gateway
8+
sectionName: empty-hostname
9+
rules:
10+
- matches:
11+
- path:
12+
type: PathPrefix
13+
value: /empty-hostname
14+
backendRefs:
15+
- name: http-echo
16+
port: 80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\.example\.com/wildcard-example-com.* hug_e2e-tests-httproute-listener-isolation_http-echo_80__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
parents:
2+
- conditions:
3+
- message: Route Accepted
4+
observedGeneration: 1
5+
reason: Accepted
6+
status: "True"
7+
type: Accepted
8+
- message: References resolved
9+
observedGeneration: 1
10+
reason: ResolvedRefs
11+
status: "True"
12+
type: ResolvedRefs
13+
controllerName: gate.haproxy.org/hug
14+
parentRef:
15+
group: gateway.networking.k8s.io
16+
kind: Gateway
17+
name: gateway
18+
sectionName: wildcard-example-com
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: Gateway
3+
metadata:
4+
name: gateway
5+
spec:
6+
gatewayClassName: haproxy
7+
listeners:
8+
- name: empty-hostname
9+
port: 8080
10+
protocol: HTTP
11+
allowedRoutes:
12+
kinds:
13+
- group: gateway.networking.k8s.io
14+
kind: HTTPRoute
15+
- name: wildcard-example-com
16+
protocol: HTTP
17+
port: 8080
18+
allowedRoutes:
19+
kinds:
20+
- group: gateway.networking.k8s.io
21+
kind: HTTPRoute
22+
hostname: "*.example.com"
23+
- name: wildcard-foo-example-com
24+
protocol: HTTP
25+
port: 8080
26+
allowedRoutes:
27+
kinds:
28+
- group: gateway.networking.k8s.io
29+
kind: HTTPRoute
30+
hostname: "*.foo.example.com"
31+
- name: abc-foo-example-com
32+
protocol: HTTP
33+
port: 8080
34+
allowedRoutes:
35+
kinds:
36+
- group: gateway.networking.k8s.io
37+
kind: HTTPRoute
38+
hostname: "abc.foo.example.com"

0 commit comments

Comments
 (0)