Skip to content

Commit 25fdbba

Browse files
committed
fix tests
1 parent 97b7df2 commit 25fdbba

1 file changed

Lines changed: 90 additions & 17 deletions

File tree

serverscom/loadbalancers_test.go

Lines changed: 90 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,18 @@ func TestLoadBalancers_GetLoadBalancer(t *testing.T) {
3737

3838
ctx := context.TODO()
3939

40+
// First search by label_selector (should return empty)
4041
collection.EXPECT().SetPerPage(100).Return(collection)
41-
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection)
4242
collection.EXPECT().SetParam("type", "l4").Return(collection)
43+
collection.EXPECT().SetParam("label_selector", "k8s.servers.com/service-id=123").Return(collection)
44+
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{}, nil)
45+
46+
service.EXPECT().Collection().Return(collection)
47+
48+
// Second search by name
49+
collection.EXPECT().SetPerPage(100).Return(collection)
50+
collection.EXPECT().SetParam("type", "l4").Return(collection)
51+
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection)
4352
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{balancer}, nil)
4453

4554
service.EXPECT().Collection().Return(collection)
@@ -81,9 +90,18 @@ func TestLoadBalancers_GetLoadBalancerNonActive(t *testing.T) {
8190

8291
ctx := context.TODO()
8392

93+
// First search by label_selector (should return empty)
8494
collection.EXPECT().SetPerPage(100).Return(collection)
85-
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection)
8695
collection.EXPECT().SetParam("type", "l4").Return(collection)
96+
collection.EXPECT().SetParam("label_selector", "k8s.servers.com/service-id=123").Return(collection)
97+
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{}, nil)
98+
99+
service.EXPECT().Collection().Return(collection)
100+
101+
// Second search by name
102+
collection.EXPECT().SetPerPage(100).Return(collection)
103+
collection.EXPECT().SetParam("type", "l4").Return(collection)
104+
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection)
87105
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{balancer}, nil)
88106

89107
service.EXPECT().Collection().Return(collection)
@@ -118,9 +136,18 @@ func TestLoadBalancers_GetLoadBalancerEmptyList(t *testing.T) {
118136

119137
ctx := context.TODO()
120138

139+
// First search by label_selector (should return empty)
121140
collection.EXPECT().SetPerPage(100).Return(collection)
122-
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection)
123141
collection.EXPECT().SetParam("type", "l4").Return(collection)
142+
collection.EXPECT().SetParam("label_selector", "k8s.servers.com/service-id=123").Return(collection)
143+
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{}, nil)
144+
145+
service.EXPECT().Collection().Return(collection)
146+
147+
// Second search by name (should return empty)
148+
collection.EXPECT().SetPerPage(100).Return(collection)
149+
collection.EXPECT().SetParam("type", "l4").Return(collection)
150+
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection)
124151
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{}, nil)
125152

126153
service.EXPECT().Collection().Return(collection)
@@ -254,9 +281,10 @@ func TestLoadBalancers_EnsureLoadBalancer(t *testing.T) {
254281
Labels: defaultLabels,
255282
}
256283

284+
// First search by label_selector (should find the balancer)
257285
collection.EXPECT().SetPerPage(100).Return(collection)
258-
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection)
259286
collection.EXPECT().SetParam("type", "l4").Return(collection)
287+
collection.EXPECT().SetParam("label_selector", "k8s.servers.com/service-id=123").Return(collection)
260288
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{balancer}, nil)
261289

262290
service.EXPECT().Collection().Return(collection)
@@ -362,12 +390,21 @@ func TestLoadBalancers_EnsureLoadBalancerWithCreate(t *testing.T) {
362390
Labels: defaultLabels,
363391
}
364392

365-
collection.EXPECT().SetPerPage(100).Return(collection).Times(2)
366-
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection).Times(2)
367-
collection.EXPECT().SetParam("type", "l4").Return(collection).Times(2)
368-
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{}, nil).Times(2)
393+
// First search by label_selector (should return empty)
394+
collection.EXPECT().SetPerPage(100).Return(collection)
395+
collection.EXPECT().SetParam("type", "l4").Return(collection)
396+
collection.EXPECT().SetParam("label_selector", "k8s.servers.com/service-id=123").Return(collection)
397+
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{}, nil)
398+
399+
service.EXPECT().Collection().Return(collection)
400+
401+
// Second search by name (should return empty)
402+
collection.EXPECT().SetPerPage(100).Return(collection)
403+
collection.EXPECT().SetParam("type", "l4").Return(collection)
404+
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection)
405+
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{}, nil)
369406

370-
service.EXPECT().Collection().Return(collection).Times(2)
407+
service.EXPECT().Collection().Return(collection)
371408
service.EXPECT().CreateL4LoadBalancer(ctx, input).Return(&l4Balancer, nil)
372409

373410
client := cli.NewClient("some")
@@ -400,6 +437,22 @@ func TestLoadBalancers_EnsureLoadBalancerWithCreate(t *testing.T) {
400437
}
401438

402439
input.ClusterID = &clusterID
440+
441+
// First search by label_selector (should return empty)
442+
collection.EXPECT().SetPerPage(100).Return(collection)
443+
collection.EXPECT().SetParam("type", "l4").Return(collection)
444+
collection.EXPECT().SetParam("label_selector", "k8s.servers.com/service-id=123").Return(collection)
445+
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{}, nil)
446+
447+
service.EXPECT().Collection().Return(collection)
448+
449+
// Second search by name (should return empty)
450+
collection.EXPECT().SetPerPage(100).Return(collection)
451+
collection.EXPECT().SetParam("type", "l4").Return(collection)
452+
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection)
453+
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{}, nil)
454+
455+
service.EXPECT().Collection().Return(collection)
403456
service.EXPECT().CreateL4LoadBalancer(ctx, input).Return(&l4Balancer, nil)
404457
status, err = balancerInterface.EnsureLoadBalancer(ctx, "cluster", &srv, []*v1.Node{&node})
405458

@@ -488,13 +541,14 @@ func TestLoadBalancers_UpdateLoadBalancer(t *testing.T) {
488541
Labels: defaultLabels,
489542
}
490543

491-
collection.EXPECT().SetPerPage(100).Return(collection).Times(2)
492-
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection).Times(2)
493-
collection.EXPECT().SetParam("type", "l4").Return(collection).Times(2)
494-
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{balancer}, nil).Times(2)
544+
// First call: search by label_selector (should find the balancer)
545+
collection.EXPECT().SetPerPage(100).Return(collection)
546+
collection.EXPECT().SetParam("type", "l4").Return(collection)
547+
collection.EXPECT().SetParam("label_selector", "k8s.servers.com/service-id=123").Return(collection)
548+
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{balancer}, nil)
495549

496-
service.EXPECT().Collection().Return(collection).Times(2)
497-
service.EXPECT().GetL4LoadBalancer(ctx, "a").Return(&l4Balancer, nil).Times(2)
550+
service.EXPECT().Collection().Return(collection)
551+
service.EXPECT().GetL4LoadBalancer(ctx, "a").Return(&l4Balancer, nil)
498552
service.EXPECT().UpdateL4LoadBalancer(ctx, "a", input).Return(&l4Balancer, nil)
499553

500554
client := cli.NewClient("some")
@@ -528,6 +582,15 @@ func TestLoadBalancers_UpdateLoadBalancer(t *testing.T) {
528582

529583
input.ClusterID = &clusterID
530584
input.SharedCluster = nil
585+
586+
// Second call: search by label_selector (should find the balancer)
587+
collection.EXPECT().SetPerPage(100).Return(collection)
588+
collection.EXPECT().SetParam("type", "l4").Return(collection)
589+
collection.EXPECT().SetParam("label_selector", "k8s.servers.com/service-id=123").Return(collection)
590+
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{balancer}, nil)
591+
592+
service.EXPECT().Collection().Return(collection)
593+
service.EXPECT().GetL4LoadBalancer(ctx, "a").Return(&l4Balancer, nil)
531594
service.EXPECT().UpdateL4LoadBalancer(ctx, "a", input).Return(&l4Balancer, nil)
532595
status, err = balancerInterface.EnsureLoadBalancer(ctx, "cluster", &srv, []*v1.Node{&node})
533596

@@ -553,9 +616,10 @@ func TestLoadBalancers_EnsureLoadBalancerDeleted(t *testing.T) {
553616

554617
ctx := context.TODO()
555618

619+
// First search by label_selector (should find the balancer)
556620
collection.EXPECT().SetPerPage(100).Return(collection)
557-
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection)
558621
collection.EXPECT().SetParam("type", "l4").Return(collection)
622+
collection.EXPECT().SetParam("label_selector", "k8s.servers.com/service-id=123").Return(collection)
559623
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{balancer}, nil)
560624

561625
service.EXPECT().Collection().Return(collection)
@@ -591,9 +655,18 @@ func TestLoadBalancers_EnsureLoadBalancerDeletedWhenBalancerAlreadyDeleted(t *te
591655

592656
ctx := context.TODO()
593657

658+
// First search by label_selector (should return empty)
659+
collection.EXPECT().SetPerPage(100).Return(collection)
660+
collection.EXPECT().SetParam("type", "l4").Return(collection)
661+
collection.EXPECT().SetParam("label_selector", "k8s.servers.com/service-id=123").Return(collection)
662+
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{}, nil)
663+
664+
service.EXPECT().Collection().Return(collection)
665+
666+
// Second search by name (should return empty)
594667
collection.EXPECT().SetPerPage(100).Return(collection)
595-
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection)
596668
collection.EXPECT().SetParam("type", "l4").Return(collection)
669+
collection.EXPECT().SetParam("search_pattern", balancerName).Return(collection)
597670
collection.EXPECT().Collect(ctx).Return([]cli.LoadBalancer{}, nil)
598671

599672
service.EXPECT().Collection().Return(collection)

0 commit comments

Comments
 (0)