@@ -2,7 +2,6 @@ package model
22
33import (
44 "github.com/stretchr/testify/assert"
5- "sigs.k8s.io/aws-load-balancer-controller/pkg/gateway/routeutils"
65 elbv2model "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2"
76 "testing"
87)
@@ -48,116 +47,3 @@ func Test_IsIPv6Supported(t *testing.T) {
4847 })
4948 }
5049}
51-
52- // Test SortRoutesByHostnamePrecedence
53- func Test_SortRoutesByHostnamePrecedence (t * testing.T ) {
54- tests := []struct {
55- name string
56- input []routeutils.RouteDescriptor
57- expected []routeutils.RouteDescriptor
58- }{
59- {
60- name : "empty routes" ,
61- input : []routeutils.RouteDescriptor {},
62- expected : []routeutils.RouteDescriptor {},
63- },
64- {
65- name : "routes with no hostnames" ,
66- input : []routeutils.RouteDescriptor {
67- & routeutils.MockRoute {Hostnames : []string {}},
68- & routeutils.MockRoute {Hostnames : []string {}},
69- },
70- expected : []routeutils.RouteDescriptor {
71- & routeutils.MockRoute {Hostnames : []string {}},
72- & routeutils.MockRoute {Hostnames : []string {}},
73- },
74- },
75- {
76- name : "mix of empty and non-empty hostnames" ,
77- input : []routeutils.RouteDescriptor {
78- & routeutils.MockRoute {Hostnames : []string {}},
79- & routeutils.MockRoute {Hostnames : []string {"example.com" }},
80- & routeutils.MockRoute {Hostnames : []string {"test.com" }},
81- },
82- expected : []routeutils.RouteDescriptor {
83- & routeutils.MockRoute {Hostnames : []string {"example.com" }},
84- & routeutils.MockRoute {Hostnames : []string {"test.com" }},
85- & routeutils.MockRoute {Hostnames : []string {}},
86- },
87- },
88- {
89- name : "with and without wildcard hostnames" ,
90- input : []routeutils.RouteDescriptor {
91- & routeutils.MockRoute {Hostnames : []string {"*.example.com" }},
92- & routeutils.MockRoute {Hostnames : []string {"test.example.com" }},
93- },
94- expected : []routeutils.RouteDescriptor {
95- & routeutils.MockRoute {Hostnames : []string {"test.example.com" }},
96- & routeutils.MockRoute {Hostnames : []string {"*.example.com" }},
97- },
98- },
99- {
100- name : "complex mixed hostnames" ,
101- input : []routeutils.RouteDescriptor {
102- & routeutils.MockRoute {Hostnames : []string {"*.example.com" }},
103- & routeutils.MockRoute {Hostnames : []string {}},
104- & routeutils.MockRoute {Hostnames : []string {"test.example.com" }},
105- & routeutils.MockRoute {Hostnames : []string {"another.example.com" }},
106- },
107- expected : []routeutils.RouteDescriptor {
108- & routeutils.MockRoute {Hostnames : []string {"another.example.com" }},
109- & routeutils.MockRoute {Hostnames : []string {"test.example.com" }},
110- & routeutils.MockRoute {Hostnames : []string {"*.example.com" }},
111- & routeutils.MockRoute {Hostnames : []string {}},
112- },
113- },
114- {
115- name : "complex mixed hostnames with multiple hostnames in each port" ,
116- input : []routeutils.RouteDescriptor {
117- & routeutils.MockRoute {Hostnames : []string {"*.example.com" , "test.details.example.com" }},
118- & routeutils.MockRoute {Hostnames : []string {}},
119- & routeutils.MockRoute {Hostnames : []string {"test.example.com" }},
120- & routeutils.MockRoute {Hostnames : []string {"another.example.com" }},
121- },
122- expected : []routeutils.RouteDescriptor {
123- & routeutils.MockRoute {Hostnames : []string {"*.example.com" , "test.details.example.com" }}, // since test.details.example.com has the highest precedence order here
124- & routeutils.MockRoute {Hostnames : []string {"another.example.com" }},
125- & routeutils.MockRoute {Hostnames : []string {"test.example.com" }},
126- & routeutils.MockRoute {Hostnames : []string {}},
127- },
128- },
129- {
130- name : "shorter hostname with more dots should have higher precedence " ,
131- input : []routeutils.RouteDescriptor {
132- & routeutils.MockRoute {Hostnames : []string {"another.example.com" }},
133- & routeutils.MockRoute {Hostnames : []string {"a.b.example.com" }},
134- & routeutils.MockRoute {Hostnames : []string {}},
135- & routeutils.MockRoute {Hostnames : []string {"*.example.com" }},
136- },
137- expected : []routeutils.RouteDescriptor {
138- & routeutils.MockRoute {Hostnames : []string {"a.b.example.com" }},
139- & routeutils.MockRoute {Hostnames : []string {"another.example.com" }},
140- & routeutils.MockRoute {Hostnames : []string {"*.example.com" }},
141- & routeutils.MockRoute {Hostnames : []string {}},
142- },
143- },
144- }
145-
146- for _ , tt := range tests {
147- t .Run (tt .name , func (t * testing.T ) {
148- // Create a copy of input to avoid modifying the test case data
149- actual := make ([]routeutils.RouteDescriptor , len (tt .input ))
150- copy (actual , tt .input )
151-
152- // Execute the sort
153- sortRoutesByHostnamePrecedence (actual )
154-
155- // Verify the result
156- assert .Equal (t , tt .expected , actual , "sorted routes should match expected order" )
157-
158- // Verify stability of sort
159- sortRoutesByHostnamePrecedence (actual )
160- assert .Equal (t , tt .expected , actual , "second sort should maintain the same order (stable sort)" )
161- })
162- }
163- }
0 commit comments