-
Notifications
You must be signed in to change notification settings - Fork 2
/
go_eureka_client_test.go
executable file
·757 lines (702 loc) · 22.8 KB
/
go_eureka_client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
// Copyright 2016 IBM Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//Package goEurekaClient Implements a go client that interacts with a eureka server
package goEurekaClient
// Pre requests: a eureka server available on http://172.17.0.2:8080/eureka/v2/
import (
"context"
"testing"
"time"
)
// Global test variables :
var testRegistrator Registrator
var testDiscovery Discovery
var testdiscoveryCache DiscoveryCache
var quitHeartBeats chan struct{}
var errChan chan error
var stopdiscoveryCacheChan context.Context
var instances []*Instance
// function setupTest creates discovery client, discovery cache client, registrator client, and registers apps to the server.
func setupTest(t *testing.T) (context.CancelFunc, error) {
quitHeartBeats = make(chan struct{})
errChan = make(chan error)
//stopdiscoveryCacheChan = make(context.Context)
var cancel context.CancelFunc
stopdiscoveryCacheChan, cancel = context.WithCancel(context.Background())
//defer cancel() // cancel when we are finished consuming integers
e := createClients()
if e != nil {
return cancel, e
}
return cancel, registerInstances(t)
}
// function createClients creates discovery client, discovery cache client and registrator client.
func createClients() error {
conf := &Config{
ConnectTimeoutSeconds: 10 * time.Second,
UseDNSForServiceUrls: false, // default false
ServiceUrls: map[string][]string{"eureka": []string{"http://172.17.0.2:8080/eureka/v2/"}},
ServerPort: 8080, // default 8080
PreferSameZone: false, // default false
RetriesCount: 3, // default 3
UseJSON: true, // default true
}
var m mockHandler = "test"
var e error
testRegistrator, e = NewRegistrator(conf, &m)
if e != nil {
return e
}
testDiscovery, e = NewDiscovery(conf, &m)
if e != nil {
return e
}
testdiscoveryCache, e = NewDiscoveryCache(conf, 7*time.Second, &m)
if e != nil {
return e
}
testdiscoveryCache.Run(stopdiscoveryCacheChan)
return e
}
// function createInstance, create anew instance with the minimal requirements in order to be registerd in the server :
func createInstance(hostName, appName, vipAddr, svipAddr string) *Instance {
return &Instance{
Application: appName,
HostName: hostName,
Status: "UP",
Datacenter: &DatacenterInfo{Class: "class", Name: "MyOwn", Metadata: DatacenterMetadata{}},
VIPAddr: vipAddr,
SecVIPAddr: svipAddr,
}
}
// function registerInstances registers 6 instances to the server.
func registerInstances(t *testing.T) error {
instances = []*Instance{createInstance("inst1", "app1", "vip1", "svip1"),
createInstance("inst2", "app1", "vip1", "svip2"),
createInstance("inst3", "app1", "vip2", "svip1"),
createInstance("inst1", "app2", "vip2", "svip2"),
createInstance("inst2", "app2", "vip2", "svip1"),
createInstance("inst3", "app2", "vip1", "svip2")}
for _, inst := range instances {
e := testRegistrator.Register(inst)
if e != nil {
return e
}
}
go sendHeartBeats(instances, t)
return nil
}
func sendHeartBeats(instances []*Instance, t *testing.T) {
for {
select {
case <-quitHeartBeats:
t.Log("quit channel recieived, stop sending heartbeats")
return
default:
for _, inst := range instances {
e := testRegistrator.Heartbeat(inst)
if e != nil {
errChan <- e
return
}
}
t.Log("heartbeats sent")
time.Sleep(30 * time.Second)
}
}
}
func tearDownTest(t *testing.T, cancel context.CancelFunc) error {
var stop struct{}
// Stop the go routine which sends heat-beats to instances.
quitHeartBeats <- stop
// Stop the discovery cache poll intervals :
cancel()
// De-register all instances from server :
for _, inst := range instances {
e := testRegistrator.Deregister(inst)
if e != nil {
t.Log("something went wrong during dregisteriation...")
return e
}
}
t.Log("Successfully de-registerd all instances from eureka server. sleep 30 seconds before return from" +
" function")
time.Sleep(30 * time.Second)
return nil
}
func TestGetInstancesByVipAddress(t *testing.T) {
t.Log("************************************************************************************************")
t.Log("Calling Setup test...")
cancel, e := setupTest(t)
if e != nil {
// send quit channel :
quitHeartBeats <- struct{}{}
cancel()
t.Errorf("Error during setup : %v", e)
return
}
t.Log("Successfully initialized discovery, discovery cache and registrator client. sleeping 30 seconds.")
t.Log("************************************************************************************************")
time.Sleep(30 * time.Second)
t.Log("Testing Get instances by vip address... ")
dicoveryInstances, err := testDiscovery.GetInstancesByVip("vip1")
if err != nil {
quitHeartBeats <- struct{}{}
t.Errorf("Error while trying to get instances from server into discovery: %v ", err)
return
}
if len(dicoveryInstances) != 3 {
quitHeartBeats <- struct{}{}
t.Errorf("Should have gotten 3 instances with vip addrees vip1, instead got %d",
len(dicoveryInstances))
return
}
numOfInstsFromApp1 := 0
numOfInstsFromApp2 := 0
numOfInstsFromInst1 := 0
numOfInstsFromInst2 := 0
numOfInstsFromsVip1 := 0
numOfInstsFromsVip2 := 0
for _, inst := range dicoveryInstances {
if inst.Application == "APP1" {
numOfInstsFromApp1++
}
if inst.Application == "APP2" {
numOfInstsFromApp2++
}
if inst.HostName == "inst1" {
numOfInstsFromInst1++
}
if inst.HostName == "inst2" {
numOfInstsFromInst2++
}
if inst.SecVIPAddr == "svip1" {
numOfInstsFromsVip1++
}
if inst.SecVIPAddr == "svip2" {
numOfInstsFromsVip2++
}
}
if numOfInstsFromApp1 != 2 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to app1 should be 2, insted : %d", numOfInstsFromApp1)
return
} else if numOfInstsFromApp2 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to app2 should be 1, insted : %d", numOfInstsFromApp2)
return
} else if numOfInstsFromInst1 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to id inst1 should be 1, insted : %d", numOfInstsFromInst1)
return
} else if numOfInstsFromInst2 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to id inst2 should be 1, insted : %d", numOfInstsFromInst2)
return
} else if numOfInstsFromsVip1 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to secure vip1 should be 1, insted : %d", numOfInstsFromsVip1)
return
} else if numOfInstsFromsVip2 != 2 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to secure vip2 should be 2, insted : %d", numOfInstsFromsVip2)
return
}
time.Sleep(10 * time.Second)
discoveryCacheInstances, err := testdiscoveryCache.GetInstancesByVip("vip1")
if err != nil {
quitHeartBeats <- struct{}{}
t.Errorf("Error while trying to get instances from discovery cache: %v ", err)
return
}
if len(discoveryCacheInstances) != 3 {
quitHeartBeats <- struct{}{}
t.Errorf("Should have gotten 3 instances with vip addrees vip1, instead got %d",
len(discoveryCacheInstances))
return
}
numOfInstsFromApp1 = 0
numOfInstsFromApp2 = 0
numOfInstsFromInst1 = 0
numOfInstsFromInst2 = 0
numOfInstsFromsVip1 = 0
numOfInstsFromsVip2 = 0
for _, inst := range discoveryCacheInstances {
if inst.Application == "APP1" {
numOfInstsFromApp1++
}
if inst.Application == "APP2" {
numOfInstsFromApp2++
}
if inst.HostName == "inst1" {
numOfInstsFromInst1++
}
if inst.HostName == "inst2" {
numOfInstsFromInst2++
}
if inst.SecVIPAddr == "svip1" {
numOfInstsFromsVip1++
}
if inst.SecVIPAddr == "svip2" {
numOfInstsFromsVip2++
}
}
if numOfInstsFromApp1 != 2 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to app1 should be 2, insted : %d", numOfInstsFromApp1)
} else if numOfInstsFromApp2 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to app2 should be 1, insted : %d", numOfInstsFromApp2)
} else if numOfInstsFromInst1 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to id inst1 should be 1, insted : %d", numOfInstsFromInst1)
} else if numOfInstsFromInst2 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to id inst2 should be 1, insted : %d", numOfInstsFromInst2)
} else if numOfInstsFromsVip1 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to secure vip1 should be 1, insted : %d", numOfInstsFromsVip1)
} else if numOfInstsFromsVip2 != 2 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to secure vip2 should be 2, insted : %d", numOfInstsFromsVip2)
}
t.Log("Successfully passed test GetInstancesByVipAddress...")
// clean :
t.Log("************************************************************************************************")
t.Log("Calling tear dorwn function...")
e = tearDownTest(t, cancel)
if e != nil {
t.Errorf("Error during tear down : : %v", e)
}
t.Log("Tear down cpmpleted succesfully")
t.Log("************************************************************************************************")
time.Sleep(30 * time.Second)
t.Log("Test Ended Successfully")
}
func TestGetInstancesBySVipAddress(t *testing.T) {
cancel, e := setupTest(t)
if e != nil {
// send quit channel :
quitHeartBeats <- struct{}{}
cancel()
t.Errorf("Error during setup : %v", e)
return
}
t.Log("Successfully initialized discovery, discovery cache and registrator client. sleeping 30 seconds.")
t.Log("************************************************************************************************")
time.Sleep(30 * time.Second)
t.Log("Testing Get instances by secure vip address... ")
dicoveryInstances, err := testDiscovery.GetInstancesBySecVip("svip2")
if err != nil {
quitHeartBeats <- struct{}{}
t.Errorf("Error while trying to get instances from server into discovery: %v ", err)
return
}
if len(dicoveryInstances) != 3 {
quitHeartBeats <- struct{}{}
t.Errorf("Should have gotten 3 instances with svip addrees svip2, instead got %d", len(dicoveryInstances))
return
}
numOfInstsFromApp1 := 0
numOfInstsFromApp2 := 0
numOfInstsFromInst1 := 0
numOfInstsFromInst2 := 0
numOfInstsFromVip1 := 0
numOfInstsFromsip2 := 0
for _, inst := range dicoveryInstances {
if inst.Application == "APP1" {
numOfInstsFromApp1++
}
if inst.Application == "APP2" {
numOfInstsFromApp2++
}
if inst.HostName == "inst1" {
numOfInstsFromInst1++
}
if inst.HostName == "inst2" {
numOfInstsFromInst2++
}
if inst.VIPAddr == "vip1" {
numOfInstsFromVip1++
}
if inst.VIPAddr == "vip2" {
numOfInstsFromsip2++
}
}
if numOfInstsFromApp1 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to app1 should be 1, insted : %d", numOfInstsFromApp1)
return
} else if numOfInstsFromApp2 != 2 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to app2 should be 2, insted : %d", numOfInstsFromApp2)
return
} else if numOfInstsFromInst1 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to id inst1 should be 1, insted : %d", numOfInstsFromInst1)
return
} else if numOfInstsFromInst2 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to id inst2 should be 1, insted : %d", numOfInstsFromInst2)
return
} else if numOfInstsFromVip1 != 2 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to vip1 should be 1, insted : %d", numOfInstsFromVip1)
return
} else if numOfInstsFromsip2 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to vip2 should be 2, insted : %d", numOfInstsFromsip2)
return
}
time.Sleep(10 * time.Second)
discoveryCacheInstances, err := testdiscoveryCache.GetInstancesBySecVip("svip2")
if err != nil {
quitHeartBeats <- struct{}{}
t.Errorf("Error while trying to get instances from discovery cache: %v ", err)
return
}
if len(discoveryCacheInstances) != 3 {
t.Errorf("Should have gotten 3 instances with svip addrees svip2, instead got %d", len(discoveryCacheInstances))
return
}
numOfInstsFromApp1 = 0
numOfInstsFromApp2 = 0
numOfInstsFromInst1 = 0
numOfInstsFromInst2 = 0
numOfInstsFromVip1 = 0
numOfInstsFromsip2 = 0
for _, inst := range discoveryCacheInstances {
if inst.Application == "APP1" {
numOfInstsFromApp1++
}
if inst.Application == "APP2" {
numOfInstsFromApp2++
}
if inst.HostName == "inst1" {
numOfInstsFromInst1++
}
if inst.HostName == "inst2" {
numOfInstsFromInst2++
}
if inst.VIPAddr == "vip1" {
numOfInstsFromVip1++
}
if inst.VIPAddr == "vip2" {
numOfInstsFromsip2++
}
}
if numOfInstsFromApp1 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to app1 should be 1, insted : %d", numOfInstsFromApp1)
return
} else if numOfInstsFromApp2 != 2 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to app2 should be 2, insted : %d", numOfInstsFromApp2)
return
} else if numOfInstsFromInst1 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to id inst1 should be 1, insted : %d", numOfInstsFromInst1)
return
} else if numOfInstsFromInst2 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to id inst2 should be 1, insted : %d", numOfInstsFromInst2)
return
} else if numOfInstsFromVip1 != 2 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to vip1 should be 1, insted : %d", numOfInstsFromVip1)
return
} else if numOfInstsFromsip2 != 1 {
quitHeartBeats <- struct{}{}
t.Errorf("Numer of instances belonging to vip2 should be 2, insted : %d", numOfInstsFromsip2)
return
}
t.Log("Successfully passed test GetInstancesBySVipAddress...")
// clean :
t.Log("************************************************************************************************")
t.Log("Calling tear down function...")
e = tearDownTest(t, cancel)
if e != nil {
t.Errorf("Error during tear down : : %v", e)
return
}
t.Log("Tear down cpmpleted succesfully")
t.Log("************************************************************************************************")
time.Sleep(30 * time.Second)
t.Log("Test Ended Successfully")
}
func TestGetInstanceByAppId(t *testing.T) {
cancel, e := setupTest(t)
if e != nil {
// send quit channel :
quitHeartBeats <- struct{}{}
cancel()
t.Errorf("Error during setup : %v", e)
return
}
t.Log("Successfully initialized discovery, discovery cache and registrator client. sleeping 30 seconds.")
t.Log("************************************************************************************************")
time.Sleep(30 * time.Second)
t.Log("Testing Get instances by application name... ")
/* Your Code here*/
dicoveryInstance, err := testDiscovery.GetInstance("app1", "inst1")
if err != nil {
t.Errorf("Error while trying to fetch instance from server: %v", err)
quitHeartBeats <- struct{}{}
return
}
if dicoveryInstance.SecVIPAddr != "svip1" {
quitHeartBeats <- struct{}{}
t.Errorf("svip of fetched instance should be svip1, instead : %s", dicoveryInstance.SecVIPAddr)
}
if dicoveryInstance.VIPAddr != "vip1" {
quitHeartBeats <- struct{}{}
t.Errorf("vip of fetched instance should be vip1, instead : %s", dicoveryInstance.VIPAddr)
return
}
_, err = testDiscovery.GetInstance("app1", "inst4")
if err == nil {
quitHeartBeats <- struct{}{}
t.Error("no instance with the id inst4 should be in the server")
return
}
_, err = testDiscovery.GetInstance("app5", "inst2")
if err == nil {
quitHeartBeats <- struct{}{}
t.Error("no instance with the app5 should be in the server")
return
}
//t.Log("sleeping 30 seconds before trying to fetch instances from cache...")
time.Sleep(30 * time.Second)
discoveryCacheInstances, err := testdiscoveryCache.GetInstance("APP1", "inst1")
if err != nil {
t.Errorf("Error while trying to fetch instance from server: %v", err)
quitHeartBeats <- struct{}{}
return
}
if discoveryCacheInstances == nil {
t.Error("Error while trying to fetch instance from server: , the isntance fetched is nill, and " +
"no error had been reported.")
quitHeartBeats <- struct{}{}
return
}
if discoveryCacheInstances.SecVIPAddr != "svip1" {
quitHeartBeats <- struct{}{}
t.Errorf("svip of fetched instance should be svip1, instead : %s", dicoveryInstance.SecVIPAddr)
}
if discoveryCacheInstances.VIPAddr != "vip1" {
quitHeartBeats <- struct{}{}
t.Errorf("vip of fetched instance should be vip1, instead : %s", dicoveryInstance.VIPAddr)
return
}
_, err = testdiscoveryCache.GetInstance("app1", "inst4")
if err == nil {
quitHeartBeats <- struct{}{}
t.Error("no instance with the id inst4 should be in the server")
return
}
_, err = testdiscoveryCache.GetInstance("app5", "inst2")
if err == nil {
quitHeartBeats <- struct{}{}
t.Error("no instance with the app5 should be in the server")
return
}
t.Log("Successfully passed test Get instances by application name...")
// clean :
t.Log("************************************************************************************************")
t.Log("Calling tear down function...")
e = tearDownTest(t, cancel)
if e != nil {
t.Errorf("Error during tear down : : %v", e)
return
}
t.Log("Tear down cpmpleted succesfully")
t.Log("************************************************************************************************")
time.Sleep(30 * time.Second)
t.Log("Test Ended Successfully")
return
}
func TestGetAllApplications(t *testing.T) {
cancel, e := setupTest(t)
if e != nil {
// send quit channel :
quitHeartBeats <- struct{}{}
cancel()
t.Errorf("Error during setup : %v", e)
return
}
t.Log("Successfully initialized discovery, discovery cache and registrator client. sleeping 30 seconds.")
t.Log("************************************************************************************************")
time.Sleep(30 * time.Second)
t.Log("Testing Get all applications... ")
/* Your Code here*/
discoveryApps, err := testDiscovery.GetApplications()
if err != nil {
t.Errorf("Error while trying to fetch all applications from server: %v", err)
quitHeartBeats <- struct{}{}
return
}
appNameFlag := 0
for _, app := range discoveryApps {
instNameFlag := 0
switch app.Name {
case "APP1":
appNameFlag++
insts := app.Instances
for _, inst := range insts {
// verify inst1:
switch inst.HostName {
case "inst1":
instNameFlag++
if inst.VIPAddr != "vip1" {
t.Errorf("for inst1 the vip address should be vip1. instead got"+
"%s", inst.VIPAddr)
quitHeartBeats <- struct{}{}
return
}
if inst.SecVIPAddr != "svip1" {
t.Errorf("for inst1 the svip address should be svip1. instead got"+
"%s", inst.SecVIPAddr)
quitHeartBeats <- struct{}{}
return
}
case "inst2":
instNameFlag++
if inst.VIPAddr != "vip1" {
t.Errorf("for inst1 the vip address should be vip1. instead got"+
"%s", inst.VIPAddr)
quitHeartBeats <- struct{}{}
return
}
if inst.SecVIPAddr != "svip2" {
t.Errorf("for inst1 the svip address should be svip2. instead got"+
"%s", inst.SecVIPAddr)
quitHeartBeats <- struct{}{}
return
}
case "inst3":
instNameFlag++
if inst.VIPAddr != "vip2" {
t.Errorf("for inst1 the vip address should be vip2. instead got"+
"%s", inst.VIPAddr)
quitHeartBeats <- struct{}{}
return
}
if inst.SecVIPAddr != "svip1" {
t.Errorf("for inst1 the svip address should be svip1. instead got"+
"%s", inst.SecVIPAddr)
quitHeartBeats <- struct{}{}
return
}
default:
t.Errorf("Unrecognized instance name %s", inst.HostName)
quitHeartBeats <- struct{}{}
return
}
}
if instNameFlag != 3 {
t.Errorf("Should be 3 instances registerd to app1, instead: %d", instNameFlag)
quitHeartBeats <- struct{}{}
return
}
case "APP2":
appNameFlag++
insts := app.Instances
for _, inst := range insts {
// verify inst1:
switch inst.HostName {
case "inst1":
instNameFlag++
if inst.VIPAddr != "vip2" {
t.Errorf("for inst1 the vip address should be vip2. instead got"+
"%s", inst.VIPAddr)
quitHeartBeats <- struct{}{}
return
}
if inst.SecVIPAddr != "svip2" {
t.Errorf("for inst1 the svip address should be svip2. instead got"+
"%s", inst.SecVIPAddr)
quitHeartBeats <- struct{}{}
return
}
case "inst2":
instNameFlag++
if inst.VIPAddr != "vip2" {
t.Errorf("for inst1 the vip address should be vip2. instead got"+
"%s", inst.VIPAddr)
quitHeartBeats <- struct{}{}
return
}
if inst.SecVIPAddr != "svip1" {
t.Errorf("for inst1 the svip address should be svip1. instead got"+
"%s", inst.SecVIPAddr)
quitHeartBeats <- struct{}{}
return
}
case "inst3":
instNameFlag++
if inst.VIPAddr != "vip1" {
t.Errorf("for inst3 the vip address should be vip1. instead got"+
"%s", inst.VIPAddr)
quitHeartBeats <- struct{}{}
return
}
if inst.SecVIPAddr != "svip2" {
t.Errorf("for inst1 the svip address should be svip2. instead got"+
"%s", inst.SecVIPAddr)
quitHeartBeats <- struct{}{}
return
}
default:
t.Errorf("Unrecognized instance name %s", inst.HostName)
quitHeartBeats <- struct{}{}
return
}
}
if instNameFlag != 3 {
t.Errorf("Should be 3 instances registerd to app2, instead: %d", instNameFlag)
quitHeartBeats <- struct{}{}
return
}
default:
t.Errorf("Unrecognized application name fetched from server, %s", app.Name)
quitHeartBeats <- struct{}{}
return
}
}
if appNameFlag != 2 {
t.Errorf("Should be 2 apps registerd to server, instead: %d", appNameFlag)
quitHeartBeats <- struct{}{}
return
}
t.Log("Successfully passed test Get applications...")
// clean :
t.Log("**************************************************************************************************")
t.Log("Calling tear down function...")
e = tearDownTest(t, cancel)
if e != nil {
t.Errorf("Error during tear down : : %v", e)
return
}
t.Log("Tear down cpmpleted succesfully")
t.Log("**************************************************************************************************")
time.Sleep(30 * time.Second)
t.Log("Test Ended Successfully")
return
}
func TestGetSpecificApplication(t *testing.T) {
return
}
func TestChangeInstanceDetails(t *testing.T) {
return
}