add ut for updatePod of kube 25/34025/1
authorLvbo163 <lv.bo163@zte.com.cn>
Mon, 5 Mar 2018 09:30:23 +0000 (17:30 +0800)
committerLvbo163 <lv.bo163@zte.com.cn>
Mon, 5 Mar 2018 09:30:23 +0000 (17:30 +0800)
Issue-ID: MSB-162

Change-Id: Id5f4e818567cb937ea2a9dc5bbe6e6dd081b5025
Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
src/kube2msb/kube_work_test.go

index f67608a..43ae17e 100644 (file)
@@ -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")
+       }
+}