From 5cc783ea45508ddfdfae656468662c4e538b7385 Mon Sep 17 00:00:00 2001 From: Lvbo163 Date: Mon, 5 Mar 2018 16:43:39 +0800 Subject: add ut for removeService of kubework Issue-ID: MSB-158 Change-Id: I7d19999433a77558dbd5bce97771eb8d43be60c7 Signed-off-by: Lvbo163 --- src/kube2msb/kube_work_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/kube2msb/kube_work_test.go b/src/kube2msb/kube_work_test.go index b3495ce..1c187c1 100644 --- a/src/kube2msb/kube_work_test.go +++ b/src/kube2msb/kube_work_test.go @@ -85,3 +85,47 @@ func msbWorkValidate(t *testing.T, queue <-chan MSBWork, service *kapi.Service, work.Action, work.IPAddress, work.ServiceInfo, action, ip, service.Name) } } + +func removeSingleServiceTest(t *testing.T, client *ClientBookKeeper, queue <-chan MSBWork, service *kapi.Service, ip string) { + // add service + client.AddService(service) + msbWorkValidate(t, queue, service, MSBWorkAddService, ip) + + // remove service + client.RemoveService(service) + msbWorkValidate(t, queue, service, MSBWorkRemoveService, ip) +} + +func TestRemoveServiceKube(t *testing.T) { + client := newClientBookKeeper() + msbWorkQueue := make(chan MSBWork, 10) + client.msbQueue = msbWorkQueue + + // exception process + // TODO ServiceKey not set , cannot check result for there would be no return + serviceWithoutServiceKey := kapi.Service{ + ObjectMeta: kapi.ObjectMeta{ + Annotations: map[string]string{}, + }, + } + client.RemoveService(&serviceWithoutServiceKey) + + // TODO service not exist , cannot check result for there would be no return + serviceNotExist := createMockService("serviceTypeClusterIP", "192.168.10.9", kapi.ServiceTypeClusterIP) + serviceNotExist.Name = "serviceNotExist" + client.RemoveService(serviceNotExist) + + // normal process + // ServiceTypeClusterIP + serviceClusterIp := createMockService("serviceTypeClusterIP", "192.168.10.10", kapi.ServiceTypeClusterIP) + removeSingleServiceTest(t, client, msbWorkQueue, serviceClusterIp, "192.168.10.10") + + // ServiceTypeNodePort + serviceNodePort := createMockService("ServiceTypeNodePort", "192.168.10.11", kapi.ServiceTypeNodePort) + removeSingleServiceTest(t, client, msbWorkQueue, serviceNodePort, "192.168.10.11") + + // ServiceTypeLoadBalancer + serviceLoadBalancer := createMockService("serviceTypeClusterIP", "192.168.10.12", kapi.ServiceTypeLoadBalancer) + serviceLoadBalancer.Spec.LoadBalancerIP = "192.168.10.12" + removeSingleServiceTest(t, client, msbWorkQueue, serviceLoadBalancer, "192.168.10.12") +} -- cgit 1.2.3-korg