Skip to content

Commit 2a30772

Browse files
committed
Create wrappers for shared function with different return signatures
1 parent 82e45c2 commit 2a30772

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

internal/state/graph/gateway_listener.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func newListenerConfiguratorFactory(
8989
},
9090
http: &listenerConfigurator{
9191
validators: []listenerValidator{
92+
validateListenerAllowedRouteKind,
9293
validateListenerLabelSelector,
9394
validateListenerHostname,
9495
validateHTTPListener,
@@ -158,8 +159,7 @@ func (c *listenerConfigurator) configure(listener v1beta1.Listener) *Listener {
158159
}
159160
}
160161

161-
cnds, supportedKinds := getAndValidateSupportedKinds(listener)
162-
conds = append(conds, cnds...)
162+
supportedKinds := getListenerSupportedKinds(listener)
163163

164164
if len(conds) > 0 {
165165
return &Listener{
@@ -211,7 +211,10 @@ func validateListenerHostname(listener v1beta1.Listener) []conditions.Condition
211211
return nil
212212
}
213213

214-
func getAndValidateSupportedKinds(listener v1beta1.Listener) ([]conditions.Condition, []v1beta1.RouteGroupKind) {
214+
func getAndValidateListenerSupportedKinds(listener v1beta1.Listener) (
215+
[]conditions.Condition,
216+
[]v1beta1.RouteGroupKind,
217+
) {
215218
if listener.AllowedRoutes == nil || listener.AllowedRoutes.Kinds == nil {
216219
return nil, []v1beta1.RouteGroupKind{
217220
{
@@ -247,6 +250,16 @@ func getAndValidateSupportedKinds(listener v1beta1.Listener) ([]conditions.Condi
247250
return conds, supportedKinds
248251
}
249252

253+
func validateListenerAllowedRouteKind(listener v1beta1.Listener) []conditions.Condition {
254+
conds, _ := getAndValidateListenerSupportedKinds(listener)
255+
return conds
256+
}
257+
258+
func getListenerSupportedKinds(listener v1beta1.Listener) []v1beta1.RouteGroupKind {
259+
_, kinds := getAndValidateListenerSupportedKinds(listener)
260+
return kinds
261+
}
262+
250263
func validateListenerLabelSelector(listener v1beta1.Listener) []conditions.Condition {
251264
if listener.AllowedRoutes != nil &&
252265
listener.AllowedRoutes.Namespaces != nil &&

internal/state/graph/gateway_listener_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func TestValidateListenerHostname(t *testing.T) {
219219
}
220220
}
221221

222-
func TestGetAndValidateSupportedKinds(t *testing.T) {
222+
func TestGetAndValidateListenerSupportedKinds(t *testing.T) {
223223
HTTPRouteGroupKind := []v1beta1.RouteGroupKind{
224224
{
225225
Kind: "HTTPRoute",
@@ -321,7 +321,7 @@ func TestGetAndValidateSupportedKinds(t *testing.T) {
321321
}
322322
}
323323

324-
conds, kinds := getAndValidateSupportedKinds(listener)
324+
conds, kinds := getAndValidateListenerSupportedKinds(listener)
325325
g.Expect(helpers.Diff(test.expected, kinds)).To(BeEmpty())
326326
if test.expectErr {
327327
g.Expect(conds).ToNot(BeEmpty())

0 commit comments

Comments
 (0)