diff options
author | Lvbo163 <lv.bo163@zte.com.cn> | 2018-03-05 16:43:39 +0800 |
---|---|---|
committer | Lvbo163 <lv.bo163@zte.com.cn> | 2018-03-05 16:43:39 +0800 |
commit | 5cc783ea45508ddfdfae656468662c4e538b7385 (patch) | |
tree | a45ff4c67a9458156f599dd4d10babca6a1ba988 /src/kube2msb | |
parent | 73f4df506751f186208c03a5223a61bb438f3130 (diff) |
add ut for removeService of kubework
Issue-ID: MSB-158
Change-Id: I7d19999433a77558dbd5bce97771eb8d43be60c7
Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
Diffstat (limited to 'src/kube2msb')
-rw-r--r-- | src/kube2msb/kube_work_test.go | 44 |
1 files changed, 44 insertions, 0 deletions
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") +} |