From a44a986e78cd1b73a1fda61a2568f4bc4001a42c Mon Sep 17 00:00:00 2001 From: Lvbo163 Date: Mon, 5 Mar 2018 17:30:23 +0800 Subject: add ut for updatePod of kube Issue-ID: MSB-162 Change-Id: Id5f4e818567cb937ea2a9dc5bbe6e6dd081b5025 Signed-off-by: Lvbo163 --- src/kube2msb/kube_work_test.go | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/kube2msb') diff --git a/src/kube2msb/kube_work_test.go b/src/kube2msb/kube_work_test.go index f67608a..43ae17e 100644 --- a/src/kube2msb/kube_work_test.go +++ b/src/kube2msb/kube_work_test.go @@ -219,7 +219,6 @@ func TestAddPodKube(t *testing.T) { } - func TestRemovePodKube(t *testing.T) { client := newClientBookKeeper() msbWorkQueue := make(chan MSBWork, 10) @@ -246,4 +245,43 @@ func TestRemovePodKube(t *testing.T) { if _, ok := client.pods[pod.Name]; ok { t.Errorf("remove pod error, pod still exists in client.pods") } -} \ No newline at end of file +} + +func TestUpdatePodKube(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 + podWithoutServiceKey := kapi.Pod{} + client.UpdatePod(&podWithoutServiceKey) + + // normal process + // update exist Pod + existPod := createMockPod("mockPod", "192.168.10.11") + client.AddPod(existPod) + msbWorkPodValidate(t, msbWorkQueue, existPod, MSBWorkAddPod) + if _, ok := client.pods[existPod.Name]; !ok { + t.Errorf("add pod error, pod not exists in client.pods") + } + // update service info + existPod.Status.PodIP = "0.0.0.0" + client.UpdatePod(existPod) + msbWorkPodValidate(t, msbWorkQueue, existPod, MSBWorkRemovePod) + msbWorkPodValidate(t, msbWorkQueue, existPod, MSBWorkAddPod) + if updatedExistPod, ok := client.pods[existPod.Name]; !ok || updatedExistPod.Status.PodIP != existPod.Status.PodIP { + t.Errorf("add pod error, pod not exists in client.pods") + } + + // update not exist service + notExistPod := createMockPod("mockNotExistPod", "192.168.10.11") + if _, ok := client.pods[notExistPod.Name]; ok { + t.Errorf("mockNotExistPod should not exist before it has been added") + } + client.UpdatePod(notExistPod) + msbWorkPodValidate(t, msbWorkQueue, notExistPod, MSBWorkAddPod) + if _, ok := client.pods[notExistPod.Name]; !ok { + t.Errorf("mockNotExistPod should not exist before it has been added") + } +} -- cgit 1.2.3-korg