Skip to content

Commit c03a5d6

Browse files
committed
Add further tests for external access ranges. Not yet working.
1 parent 79d3c99 commit c03a5d6

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

tests/load_balancer_source_ranges_test.go

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ func TestLoadBalancingSourceRanges(t *testing.T) {
8787
// be there already, when the deployment is ready, however, we have had
8888
// unstable tests in the past
8989
counter := 0
90-
for counter < 60 {
90+
var foundExternalIP string
91+
for {
9192
if svc, err := svcs.Get(eaServiceName, metav1.GetOptions{}); err == nil {
9293
spec := svc.Spec
9394
ranges := spec.LoadBalancerSourceRanges
9495
if len(ranges) != 2 {
95-
t.Errorf("LoadBalancerSourceRanges do not have length 2: %v", ranges)
96+
t.Errorf("LoadBalancerSourceRanges does not have length 2: %v", ranges)
9697
} else {
9798
if ranges[0] != "1.2.3.0/24" {
9899
t.Errorf("Expecting first LoadBalancerSourceRange to be \"1.2.3.0/24\", but ranges are: %v", ranges)
@@ -101,11 +102,56 @@ func TestLoadBalancingSourceRanges(t *testing.T) {
101102
t.Errorf("Expecting second LoadBalancerSourceRange to be \"0.0.0.0/0\", but ranges are: %v", ranges)
102103
}
103104
}
104-
return
105+
foundExternalIP = spec.LoadBalancerIP
106+
break
105107
}
106108
t.Logf("Service %s cannot be found, waiting for some time...", eaServiceName)
107109
time.Sleep(time.Second)
108110
counter += 1
111+
if counter >= 60 {
112+
t.Fatalf("Could not find service %s within 60 seconds, giving up.", eaServiceName)
113+
}
114+
}
115+
116+
// Now change the deployment spec to use different ranges:
117+
depl, err = updateDeployment(c, depl.GetName(), ns,
118+
func(spec *api.DeploymentSpec) {
119+
spec.ExternalAccess.LoadBalancerSourceRanges = []string{"4.5.0.0/16"}
120+
})
121+
if err != nil {
122+
t.Fatalf("Failed to update the deployment")
123+
}
124+
125+
// And check again:
126+
counter = 0
127+
for {
128+
time.Sleep(time.Second)
129+
if svc, err := svcs.Get(eaServiceName, metav1.GetOptions{}); err == nil {
130+
spec := svc.Spec
131+
ranges := spec.LoadBalancerSourceRanges
132+
good := true
133+
if len(ranges) != 1 {
134+
t.Logf("LoadBalancerSourceRanges does not have length 1: %v, waiting some more...", ranges)
135+
good = false
136+
} else {
137+
if ranges[0] != "4.5.0.0/16" {
138+
t.Logf("Expecting only LoadBalancerSourceRange to be \"4.5.0.0/16\", but ranges are: %v, waiting some more...", ranges)
139+
good = false
140+
} else {
141+
if spec.LoadBalancerIP != foundExternalIP {
142+
t.Errorf("Oops, the external IP of the external access service has changed: previously: %s, now: %s", foundExternalIP, spec.LoadBalancerIP)
143+
}
144+
}
145+
}
146+
if good {
147+
break
148+
}
149+
}
150+
t.Logf("Service %s cannot be found, waiting for some more time...", eaServiceName)
151+
counter += 1
152+
if counter >= 60 {
153+
t.Fatalf("Could not find changed service %s within 60 seconds, giving up.", eaServiceName)
154+
}
109155
}
110-
t.Fatalf("Could not find service %s within 60 seconds, giving up.", eaServiceName)
156+
t.Logf("Success! Service %s was changed correctly.", eaServiceName)
111157
}

0 commit comments

Comments
 (0)