Skip to content

Commit 5784818

Browse files
committed
add test code for tcproute and udproute
1 parent 0367f79 commit 5784818

File tree

4 files changed

+1317
-6
lines changed

4 files changed

+1317
-6
lines changed

internal/controller/nginx/config/stream_servers_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66
"testing"
77

8+
"github.com/go-logr/logr"
89
. "github.com/onsi/gomega"
910

1011
"github.com/nginx/nginx-gateway-fabric/v2/internal/controller/nginx/config/stream"
@@ -174,7 +175,8 @@ func TestCreateStreamServers(t *testing.T) {
174175
},
175176
}
176177

177-
streamServers := createStreamServers(conf)
178+
logger := logr.Discard()
179+
streamServers := createStreamServers(logger, conf)
178180

179181
g := NewWithT(t)
180182

@@ -405,7 +407,8 @@ func TestCreateStreamServersWithNone(t *testing.T) {
405407
TLSPassthroughServers: nil,
406408
}
407409

408-
streamServers := createStreamServers(conf)
410+
logger := logr.Discard()
411+
streamServers := createStreamServers(logger, conf)
409412

410413
g := NewWithT(t)
411414

internal/controller/state/graph/gateway_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func TestBuildGateway(t *testing.T) {
246246
foo443TLSListener := createTLSListener("foo-443-tls", "foo.example.com", 443)
247247

248248
// invalid listeners
249+
// TCP listener with hostname is invalid because TCP doesn't support hostname
249250
invalidProtocolListener := createTCPListener("invalid-protocol", "bar.example.com", 80)
250251
invalidPortListener := createHTTPListener("invalid-port", "invalid-port", 0)
251252
invalidProtectedPortListener := createHTTPListener("invalid-protected-port", "invalid-protected-port", 9113)
@@ -760,10 +761,13 @@ func TestBuildGateway(t *testing.T) {
760761
GatewayName: client.ObjectKeyFromObject(getLastCreatedGateway()),
761762
Source: invalidProtocolListener,
762763
Valid: false,
763-
Attachable: false,
764-
Conditions: conditions.NewListenerUnsupportedProtocol(
765-
`protocol: Unsupported value: "TCP": supported values: "HTTP", "HTTPS", "TLS"`,
764+
Attachable: true,
765+
Conditions: conditions.NewListenerUnsupportedValue(
766+
`hostname: Forbidden: hostname is not supported for TCP listener`,
766767
),
768+
SupportedKinds: []v1.RouteGroupKind{
769+
{Kind: kinds.TCPRoute, Group: helpers.GetPointer[v1.Group](v1.GroupName)},
770+
},
767771
Routes: map[RouteKey]*L7Route{},
768772
L4Routes: map[L4RouteKey]*L4Route{},
769773
},
@@ -775,7 +779,7 @@ func TestBuildGateway(t *testing.T) {
775779
Valid: true,
776780
},
777781
},
778-
name: "invalid listener protocol",
782+
name: "invalid listener protocol", // Actually tests TCP listener with invalid hostname
779783
},
780784
{
781785
gateway: createGateway(

0 commit comments

Comments
 (0)