Skip to content

Commit 24a5276

Browse files
author
Henry Wagner
committed
add unit test for reserved IP LB creation/update
1 parent b1021f4 commit 24a5276

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

cloud/linode/loadbalancers_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,6 +3009,8 @@ func testUpdateLoadBalancerDeleteFirewallRemoveID(t *testing.T, client *linodego
30093009

30103010
func testUpdateLoadBalancerAddReservedIP(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) {
30113011
t.Helper()
3012+
clusterName := "linodelb"
3013+
region := "us-west"
30123014

30133015
svc := &v1.Service{
30143016
ObjectMeta: metav1.ObjectMeta{
@@ -3041,12 +3043,12 @@ func testUpdateLoadBalancerAddReservedIP(t *testing.T, client *linodego.Client,
30413043
},
30423044
}
30433045

3044-
lb, assertion := newLoadbalancers(client, "us-west").(*loadbalancers)
3046+
lb, assertion := newLoadbalancers(client, region).(*loadbalancers)
30453047
if !assertion {
30463048
t.Error("type assertion failed")
30473049
}
30483050
defer func() {
3049-
_ = lb.EnsureLoadBalancerDeleted(t.Context(), "linodelb", svc)
3051+
_ = lb.EnsureLoadBalancerDeleted(t.Context(), clusterName, svc)
30503052
}()
30513053

30523054
fakeClientset := fake.NewSimpleClientset()
@@ -3059,6 +3061,7 @@ func testUpdateLoadBalancerAddReservedIP(t *testing.T, client *linodego.Client,
30593061
t.Fatalf("failed to create NodeBalancer: %s", err)
30603062
}
30613063

3064+
initialIP := string(*nodeBalancer.IPv4)
30623065
svc.Status.LoadBalancer = *makeLoadBalancerStatus(svc, nodeBalancer)
30633066

30643067
ipaddr, err := client.ReserveIPAddress(context.TODO(), linodego.ReserveIPOptions{
@@ -3073,10 +3076,22 @@ func testUpdateLoadBalancerAddReservedIP(t *testing.T, client *linodego.Client,
30733076
annotations.AnnLinodeLoadBalancerIPv4: ipaddr.Address,
30743077
})
30753078

3076-
err = lb.UpdateLoadBalancer(t.Context(), "linodelb", svc, nodes)
3079+
err = lb.UpdateLoadBalancer(t.Context(), "", svc, nodes)
30773080
if err != nil {
30783081
t.Errorf("UpdateLoadBalancer returned an error while updated annotations: %s", err)
30793082
}
3083+
3084+
status, _, err := lb.GetLoadBalancer(t.Context(), clusterName, svc)
3085+
if status.Ingress[0].IP != initialIP {
3086+
t.Fatalf("IP should not have changed in service status: %s", err)
3087+
}
3088+
3089+
event, _ := fakeClientset.CoreV1().Events("").Get(t.Context(),
3090+
eventIPChangeIgnoredWarning,
3091+
metav1.GetOptions{})
3092+
if event == nil {
3093+
t.Fatalf("failed to generate %s event: %s", eventIPChangeIgnoredWarning, err)
3094+
}
30803095
}
30813096

30823097
func testUpdateLoadBalancerAddNodeBalancerID(t *testing.T, client *linodego.Client, fakeAPI *fakeAPI) {

0 commit comments

Comments
 (0)