@@ -149,7 +149,7 @@ func TestValidateGateway(t *testing.T) {
149
149
},
150
150
expectErrsOnFields : []string {"spec.listeners[1].name" },
151
151
},
152
- "combination of port, protocol, and name are not unique for each listener" : {
152
+ "combination of port, protocol, and hostname are not unique for each listener" : {
153
153
mutate : func (gw * gatewayv1b1.Gateway ) {
154
154
hostnameFoo := gatewayv1b1 .Hostname ("foo.com" )
155
155
gw .Spec .Listeners [0 ].Name = "foo"
@@ -167,6 +167,86 @@ func TestValidateGateway(t *testing.T) {
167
167
},
168
168
expectErrsOnFields : []string {"spec.listeners[1]" },
169
169
},
170
+ "combination of port and protocol are not unique for each listenr when hostnames not set" : {
171
+ mutate : func (gw * gatewayv1b1.Gateway ) {
172
+ gw .Spec .Listeners [0 ].Name = "foo"
173
+ gw .Spec .Listeners [0 ].Protocol = gatewayv1b1 .HTTPProtocolType
174
+ gw .Spec .Listeners [0 ].Port = 80
175
+ gw .Spec .Listeners = append (gw .Spec .Listeners ,
176
+ gatewayv1b1.Listener {
177
+ Name : "bar" ,
178
+ Protocol : gatewayv1b1 .HTTPProtocolType ,
179
+ Port : 80 ,
180
+ },
181
+ )
182
+ },
183
+ expectErrsOnFields : []string {"spec.listeners[1]" },
184
+ },
185
+ "port is unique when protocol and hostname are the same" : {
186
+ mutate : func (gw * gatewayv1b1.Gateway ) {
187
+ hostnameFoo := gatewayv1b1 .Hostname ("foo.com" )
188
+ gw .Spec .Listeners [0 ].Name = "foo"
189
+ gw .Spec .Listeners [0 ].Hostname = & hostnameFoo
190
+ gw .Spec .Listeners [0 ].Protocol = gatewayv1b1 .HTTPProtocolType
191
+ gw .Spec .Listeners [0 ].Port = 80
192
+ gw .Spec .Listeners = append (gw .Spec .Listeners ,
193
+ gatewayv1b1.Listener {
194
+ Name : "bar" ,
195
+ Hostname : & hostnameFoo ,
196
+ Protocol : gatewayv1b1 .HTTPProtocolType ,
197
+ Port : 8080 ,
198
+ },
199
+ )
200
+ },
201
+ expectErrsOnFields : nil ,
202
+ },
203
+ "hostname is unique when protoco and port are the same" : {
204
+ mutate : func (gw * gatewayv1b1.Gateway ) {
205
+ hostnameFoo := gatewayv1b1 .Hostname ("foo.com" )
206
+ hostnameBar := gatewayv1b1 .Hostname ("bar.com" )
207
+ gw .Spec .Listeners [0 ].Name = "foo"
208
+ gw .Spec .Listeners [0 ].Hostname = & hostnameFoo
209
+ gw .Spec .Listeners [0 ].Protocol = gatewayv1b1 .HTTPProtocolType
210
+ gw .Spec .Listeners [0 ].Port = 80
211
+ gw .Spec .Listeners = append (gw .Spec .Listeners ,
212
+ gatewayv1b1.Listener {
213
+ Name : "bar" ,
214
+ Hostname : & hostnameBar ,
215
+ Protocol : gatewayv1b1 .HTTPProtocolType ,
216
+ Port : 80 ,
217
+ },
218
+ )
219
+ },
220
+ expectErrsOnFields : nil ,
221
+ },
222
+ "protocol is unique when port and hostname are the same" : {
223
+ mutate : func (gw * gatewayv1b1.Gateway ) {
224
+ hostnameFoo := gatewayv1b1 .Hostname ("foo.com" )
225
+ tlsConfigFoo := tlsConfig
226
+ tlsModeFoo := gatewayv1b1 .TLSModeType ("Terminate" )
227
+ tlsConfigFoo .Mode = & tlsModeFoo
228
+ tlsConfigFoo .CertificateRefs = []gatewayv1b1.SecretObjectReference {
229
+ {
230
+ Name : "FooCertificateRefs" ,
231
+ },
232
+ }
233
+ gw .Spec .Listeners [0 ].Name = "foo"
234
+ gw .Spec .Listeners [0 ].Hostname = & hostnameFoo
235
+ gw .Spec .Listeners [0 ].Protocol = gatewayv1b1 .HTTPSProtocolType
236
+ gw .Spec .Listeners [0 ].Port = 8000
237
+ gw .Spec .Listeners [0 ].TLS = & tlsConfigFoo
238
+ gw .Spec .Listeners = append (gw .Spec .Listeners ,
239
+ gatewayv1b1.Listener {
240
+ Name : "bar" ,
241
+ Hostname : & hostnameFoo ,
242
+ Protocol : gatewayv1b1 .TLSProtocolType ,
243
+ Port : 8000 ,
244
+ TLS : & tlsConfigFoo ,
245
+ },
246
+ )
247
+ },
248
+ expectErrsOnFields : nil ,
249
+ },
170
250
}
171
251
172
252
for name , tc := range testCases {
0 commit comments