Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyDumaine committed May 9, 2024
1 parent d6c45e4 commit bea7b45
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions cloud/linode/cilium_loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func TestCiliumCCMLoadBalancers(t *testing.T) {
name: "Create Cilium Load Balancer With default loadBalancerClass set",
f: testCreateWithDefaultLBCilium,
},
{
name: "Create Cilium Load Balancer With default loadBalancerClass set for nodebalancer service",
f: testCreateWithDefaultLBCiliumNodebalancher,
},
{
name: "Create Cilium Load Balancer With no existing IP holder nanode",
f: testCreateWithNoExistingIPHolder,
Expand All @@ -84,6 +88,10 @@ func TestCiliumCCMLoadBalancers(t *testing.T) {
name: "Delete Cilium Load Balancer",
f: testEnsureCiliumLoadBalancerDeleted,
},
{
name: "Delete NodeBalancer With default loadBalancerClass set to Cilium",
f: testDeleteNBWithDefaultLBCilium,
},
}
for _, tc := range testCases {
ctrl := gomock.NewController(t)
Expand Down Expand Up @@ -246,6 +254,32 @@ func testCreateWithDefaultLBCilium(t *testing.T, mc *mocks.MockClient) {
}
}

func testCreateWithDefaultLBCiliumNodebalancher(t *testing.T, mc *mocks.MockClient) {
Options.BGPNodeSelector = "cilium-bgp-peering=true"
svc := createTestService(Pointer(nodeBalancerLBType))

kubeClient := fake.NewSimpleClientset()
ciliumClient := &fakev2alpha1.FakeCiliumV2alpha1{Fake: &kubeClient.Fake}
addService(t, kubeClient, svc)
lb := &loadbalancers{mc, "us-west", kubeClient, ciliumClient, ciliumLBType}

mc.EXPECT().CreateNodeBalancer(gomock.Any(), gomock.Any()).Times(1).Return(&linodego.NodeBalancer{
ID: 12345,
Label: Pointer("foobar"),
Region: "us-west",
Hostname: Pointer("foobar-nb"),
IPv4: Pointer("1.2.3.4"),
}, nil)

lbStatus, err := lb.EnsureLoadBalancer(context.TODO(), "linodelb", svc, nodes)
if err != nil {
t.Fatalf("expected a nil error, got %v", err)
}
if lbStatus == nil {
t.Fatal("expected non-nil lbStatus")
}
}

func testCreateWithNoExistingIPHolder(t *testing.T, mc *mocks.MockClient) {
Options.BGPNodeSelector = "cilium-bgp-peering=true"
svc := createTestService(nil)
Expand Down Expand Up @@ -316,3 +350,30 @@ func testEnsureCiliumLoadBalancerDeleted(t *testing.T, mc *mocks.MockClient) {
t.Fatalf("expected a nil error, got %v", err)
}
}

func testDeleteNBWithDefaultLBCilium(t *testing.T, mc *mocks.MockClient) {
Options.BGPNodeSelector = "cilium-bgp-peering=true"
svc := createTestService(Pointer(nodeBalancerLBType))

kubeClient := fake.NewSimpleClientset()
ciliumClient := &fakev2alpha1.FakeCiliumV2alpha1{Fake: &kubeClient.Fake}
addService(t, kubeClient, svc)
lb := &loadbalancers{mc, "us-west", kubeClient, ciliumClient, ciliumLBType}

dummySharedIP := "45.76.101.26"
svc.Status.LoadBalancer = v1.LoadBalancerStatus{Ingress: []v1.LoadBalancerIngress{{IP: dummySharedIP}}}

mc.EXPECT().ListNodeBalancers(gomock.Any(), gomock.Any()).Times(1).Return([]linodego.NodeBalancer{{
ID: 12345,
Label: Pointer("foobar"),
Region: "us-west",
Hostname: Pointer("foobar-nb"),
IPv4: Pointer("1.2.3.4"),
}}, nil)
mc.EXPECT().DeleteNodeBalancer(gomock.Any(), gomock.Any()).Times(1).Return(nil)

err := lb.EnsureLoadBalancerDeleted(context.TODO(), "linodelb", svc)
if err != nil {
t.Fatalf("expected a nil error, got %v", err)
}
}

0 comments on commit bea7b45

Please sign in to comment.