aboutsummaryrefslogtreecommitdiffstats
path: root/src/kube2msb
diff options
context:
space:
mode:
authorLvbo163 <lv.bo163@zte.com.cn>2018-03-05 17:30:23 +0800
committerLvbo163 <lv.bo163@zte.com.cn>2018-03-05 17:30:23 +0800
commita44a986e78cd1b73a1fda61a2568f4bc4001a42c (patch)
treec9e7fdb78995abeb0b343d4268037a0cf7f018df /src/kube2msb
parent6dc335acbf4d9e9d3b036e2170a1d7b78801185a (diff)
add ut for updatePod of kube
Issue-ID: MSB-162 Change-Id: Id5f4e818567cb937ea2a9dc5bbe6e6dd081b5025 Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
Diffstat (limited to 'src/kube2msb')
-rw-r--r--src/kube2msb/kube_work_test.go42
1 files changed, 40 insertions, 2 deletions
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")
+ }
+}