@@ -149,6 +149,10 @@ func (s *ServiceInitiationSuite) TestLoadExistingBackend() {
149149 {Name : "s2" , Address : "127.1.1.2" , Port : & serverPort },
150150 {Name : "s3" , Address : "127.1.1.3" , Port : & serverPort },
151151 {Name : "s4" , Address : "127.1.1.4" , Port : & serverPort },
152+ {Name : "s5" , Address : "127.1.1.5" }, // ServiceInstance supports nil port
153+ {Name : "s6" , Address : "127.1.1.6" },
154+ {Name : "s7" , Address : "127.1.1.7" },
155+ {Name : "s8" , Address : "127.1.1.8" },
152156 }
153157 s .Nil (s .createExistingService (servers ))
154158
@@ -165,7 +169,11 @@ func (s *ServiceInitiationSuite) TestLoadExistingBackend() {
165169 if i < len (servers ) {
166170 s .Equal (server .Name , servers [i ].Name )
167171 s .Equal (server .Address , servers [i ].Address )
168- s .Equal (* server .Port , * servers [i ].Port )
172+ if server .Port != nil {
173+ s .Equal (* server .Port , * servers [i ].Port )
174+ } else {
175+ s .Nil (servers [i ].Port )
176+ }
169177 } else {
170178 s .Equal (server .Address , "127.0.0.1" )
171179 s .Equal (* server .Port , int64 (80 ))
@@ -240,10 +248,10 @@ func (s *ServiceUpdateSuit) AfterTest(suiteName, testName string) {
240248
241249func (s * ServiceUpdateSuit ) TestFirstUpdate () {
242250 servers := []configuration.ServiceServer {
243- {Address : "127.1.1.1" , Port : 81 },
244- {Address : "127.1.1.2" , Port : 82 },
245- {Address : "127.1.1.3" , Port : 83 },
246- {Address : "127.1.1.4" , Port : 84 },
251+ {Address : "127.1.1.1" , Port : misc . Int64P ( 81 ) },
252+ {Address : "127.1.1.2" , Port : misc . Int64P ( 82 ) },
253+ {Address : "127.1.1.3" , Port : misc . Int64P ( 83 ) },
254+ {Address : "127.1.1.4" , Port : misc . Int64P ( 84 ) },
247255 }
248256 r , err := s .service .Update (servers )
249257 s .True (r )
@@ -257,7 +265,7 @@ func (s *ServiceUpdateSuit) validateUpdateResult(expected []configuration.Servic
257265 for i , server := range servers {
258266 if i < len (expected ) {
259267 s .Equal (expected [i ].Address , server .Address )
260- s .Equal (expected [i ].Port , int ( * server .Port ) )
268+ s .Equal (* expected [i ].Port , * server .Port )
261269 s .NotEqual ("enabled" , server .Maintenance )
262270 } else {
263271 s .Equal ("127.0.0.1" , server .Address )
@@ -269,18 +277,18 @@ func (s *ServiceUpdateSuit) validateUpdateResult(expected []configuration.Servic
269277
270278func (s * ServiceUpdateSuit ) TestSecondUpdateWithDeletedServer () {
271279 servers := []configuration.ServiceServer {
272- {Address : "127.1.1.1" , Port : 81 },
273- {Address : "127.1.1.2" , Port : 82 },
274- {Address : "127.1.1.3" , Port : 83 },
275- {Address : "127.1.1.4" , Port : 84 },
280+ {Address : "127.1.1.1" , Port : misc . Int64P ( 81 ) },
281+ {Address : "127.1.1.2" , Port : misc . Int64P ( 82 ) },
282+ {Address : "127.1.1.3" , Port : misc . Int64P ( 83 ) },
283+ {Address : "127.1.1.4" , Port : misc . Int64P ( 84 ) },
276284 }
277285 r , err := s .service .Update (servers )
278286 s .True (r )
279287 s .Nil (err )
280288 servers = []configuration.ServiceServer {
281- {Address : "127.1.1.1" , Port : 81 },
282- {Address : "127.1.1.3" , Port : 83 },
283- {Address : "127.1.1.4" , Port : 84 },
289+ {Address : "127.1.1.1" , Port : misc . Int64P ( 81 ) },
290+ {Address : "127.1.1.3" , Port : misc . Int64P ( 83 ) },
291+ {Address : "127.1.1.4" , Port : misc . Int64P ( 84 ) },
284292 }
285293 r , err = s .service .Update (servers )
286294 s .True (r )
@@ -290,30 +298,30 @@ func (s *ServiceUpdateSuit) TestSecondUpdateWithDeletedServer() {
290298 // In this case server 127.1.1.2 got removed and the last enabled server from the remaining ones
291299 // gets moved into its slot, in this case 127.1.1.4
292300 expected := []configuration.ServiceServer {
293- {Address : "127.1.1.1" , Port : 81 },
294- {Address : "127.1.1.4" , Port : 84 },
295- {Address : "127.1.1.3" , Port : 83 },
301+ {Address : "127.1.1.1" , Port : misc . Int64P ( 81 ) },
302+ {Address : "127.1.1.4" , Port : misc . Int64P ( 84 ) },
303+ {Address : "127.1.1.3" , Port : misc . Int64P ( 83 ) },
296304 }
297305 s .validateUpdateResult (expected )
298306}
299307
300308func (s * ServiceUpdateSuit ) TestSecondUpdateWithNewAndRemovedServers () {
301309 servers := []configuration.ServiceServer {
302- {Address : "127.1.1.1" , Port : 81 },
303- {Address : "127.1.1.2" , Port : 82 },
304- {Address : "127.1.1.3" , Port : 83 },
305- {Address : "127.1.1.4" , Port : 84 },
310+ {Address : "127.1.1.1" , Port : misc . Int64P ( 81 ) },
311+ {Address : "127.1.1.2" , Port : misc . Int64P ( 82 ) },
312+ {Address : "127.1.1.3" , Port : misc . Int64P ( 83 ) },
313+ {Address : "127.1.1.4" , Port : misc . Int64P ( 84 ) },
306314 }
307315 r , err := s .service .Update (servers )
308316 s .True (r )
309317 s .Nil (err )
310318 servers = []configuration.ServiceServer {
311- {Address : "127.1.1.1" , Port : 81 },
312- {Address : "127.1.1.4" , Port : 84 },
313- {Address : "127.1.1.5" , Port : 85 },
314- {Address : "127.1.1.6" , Port : 86 },
315- {Address : "127.1.1.7" , Port : 87 },
316- {Address : "127.1.1.2" , Port : 82 },
319+ {Address : "127.1.1.1" , Port : misc . Int64P ( 81 ) },
320+ {Address : "127.1.1.4" , Port : misc . Int64P ( 84 ) },
321+ {Address : "127.1.1.5" , Port : misc . Int64P ( 85 ) },
322+ {Address : "127.1.1.6" , Port : misc . Int64P ( 86 ) },
323+ {Address : "127.1.1.7" , Port : misc . Int64P ( 87 ) },
324+ {Address : "127.1.1.2" , Port : misc . Int64P ( 82 ) },
317325 }
318326 r , err = s .service .Update (servers )
319327 s .True (r )
@@ -323,22 +331,22 @@ func (s *ServiceUpdateSuit) TestSecondUpdateWithNewAndRemovedServers() {
323331 // The first new server will be placed in place of server 127.1.1.3 which is 127.1.1.5.
324332 // The remaining new servers will be added to the end.
325333 expected := []configuration.ServiceServer {
326- {Address : "127.1.1.1" , Port : 81 },
327- {Address : "127.1.1.2" , Port : 82 },
328- {Address : "127.1.1.5" , Port : 85 },
329- {Address : "127.1.1.4" , Port : 84 },
330- {Address : "127.1.1.6" , Port : 86 },
331- {Address : "127.1.1.7" , Port : 87 },
334+ {Address : "127.1.1.1" , Port : misc . Int64P ( 81 ) },
335+ {Address : "127.1.1.2" , Port : misc . Int64P ( 82 ) },
336+ {Address : "127.1.1.5" , Port : misc . Int64P ( 85 ) },
337+ {Address : "127.1.1.4" , Port : misc . Int64P ( 84 ) },
338+ {Address : "127.1.1.6" , Port : misc . Int64P ( 86 ) },
339+ {Address : "127.1.1.7" , Port : misc . Int64P ( 87 ) },
332340 }
333341 s .validateUpdateResult (expected )
334342}
335343
336344func (s * ServiceUpdateSuit ) TestSecondUpdateWithNoChanges () {
337345 servers := []configuration.ServiceServer {
338- {Address : "127.1.1.1" , Port : 81 },
339- {Address : "127.1.1.2" , Port : 82 },
340- {Address : "127.1.1.3" , Port : 83 },
341- {Address : "127.1.1.4" , Port : 84 },
346+ {Address : "127.1.1.1" , Port : misc . Int64P ( 81 ) },
347+ {Address : "127.1.1.2" , Port : misc . Int64P ( 82 ) },
348+ {Address : "127.1.1.3" , Port : misc . Int64P ( 83 ) },
349+ {Address : "127.1.1.4" , Port : misc . Int64P ( 84 ) },
342350 }
343351 r , err := s .service .Update (servers )
344352 s .True (r )
@@ -378,7 +386,7 @@ func (s *ServiceUpdateSuit) generateServers(count int) []configuration.ServiceSe
378386 for i := 0 ; i < count ; i ++ {
379387 servers = append (servers , configuration.ServiceServer {
380388 Address : fmt .Sprintf ("127.1.1.%d" , i ),
381- Port : 80 + i ,
389+ Port : misc . Int64P ( 80 + i ) ,
382390 })
383391 }
384392 return servers
0 commit comments