@@ -136,14 +136,117 @@ func TestValidateGateway(t *testing.T) {
136
136
},
137
137
"names are not unique within the Gateway" : {
138
138
mutate : func (gw * gatewayv1b1.Gateway ) {
139
+ hostnameFoo := gatewayv1b1 .Hostname ("foo.com" )
140
+ hostnameBar := gatewayv1b1 .Hostname ("bar.com" )
139
141
gw .Spec .Listeners [0 ].Name = "foo"
140
- gw .Spec .Listeners = append (gw .Spec .Listeners , gatewayv1b1.Listener {
141
- Name : "foo" ,
142
- },
142
+ gw .Spec .Listeners [0 ].Hostname = & hostnameFoo
143
+ gw .Spec .Listeners = append (gw .Spec .Listeners ,
144
+ gatewayv1b1.Listener {
145
+ Name : "foo" ,
146
+ Hostname : & hostnameBar ,
147
+ },
143
148
)
144
149
},
145
150
expectErrsOnFields : []string {"spec.listeners[1].name" },
146
151
},
152
+ "combination of port, protocol, and hostname are not unique for each listener" : {
153
+ mutate : func (gw * gatewayv1b1.Gateway ) {
154
+ hostnameFoo := gatewayv1b1 .Hostname ("foo.com" )
155
+ gw .Spec .Listeners [0 ].Name = "foo"
156
+ gw .Spec .Listeners [0 ].Hostname = & hostnameFoo
157
+ gw .Spec .Listeners [0 ].Protocol = gatewayv1b1 .HTTPProtocolType
158
+ gw .Spec .Listeners [0 ].Port = 80
159
+ gw .Spec .Listeners = append (gw .Spec .Listeners ,
160
+ gatewayv1b1.Listener {
161
+ Name : "bar" ,
162
+ Hostname : & hostnameFoo ,
163
+ Protocol : gatewayv1b1 .HTTPProtocolType ,
164
+ Port : 80 ,
165
+ },
166
+ )
167
+ },
168
+ expectErrsOnFields : []string {"spec.listeners[1]" },
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 protocol 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
+ },
147
250
}
148
251
149
252
for name , tc := range testCases {
0 commit comments